ZQuest Classic Coverage Report


Directory: src/
File: src/zq/zq_class.cpp
Date: 2024-06-03 19:33:09
Exec Total Coverage
Lines: 2775 8316 33.4%
Functions: 76 290 26.2%
Branches: 2400 7183 33.4%

Line Branch Exec Source
1 #include <chrono>
2 #include <cstring>
3 #include <exception>
4 #include <string>
5 #include <stdexcept>
6 #include <map>
7
8 #include "base/general.h"
9 #include "base/version.h"
10 #include "dialog/info.h"
11 #include "metadata/metadata.h"
12
13 #include "base/qrs.h"
14 #include "base/dmap.h"
15 #include "base/packfile.h"
16 #include "base/cpool.h"
17 #include "base/autocombo.h"
18 #include "base/gui.h"
19 #include "base/msgstr.h"
20 #include "zc/zelda.h"
21 #include "zq/zq_class.h"
22 #include "zq/zq_misc.h"
23 #include "zq/zquest.h"
24 #include "qst.h"
25 #include "base/colors.h"
26 #include "tiles.h"
27 #include "zq/zquestdat.h"
28 #include "base/zsys.h"
29 #include "sprite.h"
30 #include "items.h"
31 #include "zc/zc_sys.h"
32 #include "md5.h"
33 #include "zc/zc_custom.h"
34 #include "subscr.h"
35 #include "zq/zq_strings.h"
36 #include "zq/zq_subscr.h"
37 #include "zc/ffscript.h"
38 #include "base/util.h"
39 #include "zq/zq_files.h"
40 #include "dialog/alert.h"
41 #include "slopes.h"
42 #include "drawing.h"
43 #include "zinfo.h"
44 #include "zq/render_minimap.h"
45 #include "base/mapscr.h"
46 #include <fmt/format.h>
47 #include <filesystem>
48
49 #ifdef __EMSCRIPTEN__
50 #include "base/emscripten_utils.h"
51 #endif
52
53 namespace fs = std::filesystem;
54
55 using namespace util;
56 extern FFScript FFCore;
57
58 extern ZModule zcm;
59 extern zcmodule moduledata;
60 extern uint8_t ViewLayer3BG, ViewLayer2BG;
61 extern int32_t LayerDitherBG, LayerDitherSz;
62 extern bool NoHighlightLayer0;
63
64 using std::string;
65 using std::pair;
66 #define EPSILON 0.01 // Define your own tolerance
67 #define FLOAT_EQ(x,v) (((v - EPSILON) < x) && (x <( v + EPSILON)))
68
69 #define COLOR_SOLID vc(4)
70 #define COLOR_SLOPE vc(13)
71 #define COLOR_LADDER vc(6)
72 //#define COLOR_EFFECT vc(10)
73
74 //const char zqsheader[30]="ZQuest Classic String Table\n\x01";
75 extern char msgbuf[MSG_NEW_SIZE*8];
76
77 extern string zScript;
78
79 9 zmap Map;
80 int32_t prv_mode=0;
81 int16_t ffposx[MAXFFCS];
82 int16_t ffposy[MAXFFCS];
83 int32_t ffprvx[MAXFFCS];
84 int32_t ffprvy[MAXFFCS];
85 void init_ffpos()
86 {
87 for (word q = 0; q < MAXFFCS; ++q)
88 {
89 ffposx[q] = -1000;
90 ffposy[q] = -1000;
91 ffprvx[q] = -10000000;
92 ffprvy[q] = -10000000;
93 }
94 }
95
96 bool save_warn=true;
97
98 int32_t COMBOPOS(int32_t x, int32_t y)
99 {
100 return (((y) & 0xF0) + ((x) >> 4));
101 }
102 int32_t COMBOPOS_B(int32_t x, int32_t y)
103 {
104 if(unsigned(x) >= 256 || unsigned(y) >= 176)
105 return -1;
106 return COMBOPOS(x,y);
107 }
108 int32_t COMBOX(int32_t pos)
109 {
110 return ((pos) % 16 * 16);
111 }
112 int32_t COMBOY(int32_t pos)
113 {
114 return ((pos) & 0xF0);
115 }
116
117 void reset_dmap(int32_t index)
118 {
119 bound(index,0,MAXDMAPS-1);
120 DMaps[index].clear();
121 DMaps[index].title = "";
122 sprintf(DMaps[index].intro, " ");
123 }
124
125 void reset_dmaps()
126 {
127 for(int32_t i=0; i<MAXDMAPS; i++)
128 reset_dmap(i);
129 }
130
131 void truncate_dmap_title(std::string& title)
132 {
133 title.resize(21, ' ');
134 }
135
136 mapscr* zmap::get_prvscr()
137 {
138 return &prvscr;
139 }
140
141
7/12
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 108 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 90 times.
✓ Branch 7 taken 18 times.
✓ Branch 8 taken 18 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 18 times.
108 zmap::zmap()
142 {
143 18 can_paste=false;
144 18 prv_cmbcycle=0;
145 18 prv_advance=0;
146 18 prv_freeze=0;
147 18 copyffc=-1;
148
149 18 memset(scrpos, 0, sizeof(scrpos));
150 18 screens=NULL;
151 18 prv_time=0;
152 18 prv_scr=0;
153 18 prv_map=0;
154 18 copyscr=0;
155 18 currscr=0;
156 18 copymap=0;
157 18 currmap=0;
158 18 layer_target_map = 0;
159 18 layer_target_scr = 0;
160 18 layer_target_multiple = 0;
161
162 18 }
163 18 zmap::~zmap()
164 {
165 18 }
166
167 9 void zmap::clear()
168 {
169
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 *this = zmap();
170 9 }
171 void zmap::force_refr_pointer()
172 {
173 if(unsigned(currmap) > map_count || (currmap*MAPSCRS > TheMaps.size()))
174 screens = nullptr;
175 else screens = &TheMaps[currmap*MAPSCRS];
176 }
177 bool zmap::CanUndo()
178 {
179 return undo_stack.size() > 0;
180 }
181 bool zmap::CanRedo()
182 {
183 return redo_stack.size() > 0;
184 }
185 bool zmap::CanPaste()
186 {
187 return can_paste;
188 }
189 int32_t zmap::CopyScr()
190 {
191 return (copymap<<8)+copyscr;
192 }
193 int32_t zmap::getCopyFFC()
194 {
195 return copyffc;
196 }
197 set_ffc_command::data_t zmap::getCopyFFCData()
198 {
199 return set_ffc_command::create_data(copymapscr.ffcs[copyffc]);
200 }
201 29 int32_t zmap::getMapCount()
202 {
203 29 return map_count;
204 }
205 int32_t zmap::getLayerTargetMap()
206 {
207 return layer_target_map;
208 }
209 int32_t zmap::getLayerTargetScr()
210 {
211 return layer_target_scr;
212 }
213 int32_t zmap::getLayerTargetMultiple()
214 {
215 return layer_target_multiple;
216 }
217 bool zmap::isDungeon(int32_t scr)
218 {
219 for(int32_t i=0; i<4; i++)
220 {
221 if(screens[scr].data[i]!=screens[TEMPLATE].data[i])
222 {
223 return false;
224 }
225 }
226
227 return true;
228 }
229
230 bool zmap::clearall(bool validate)
231 {
232 Color=0;
233 char tbuf[10];
234
235 if((header.templatepath[0]!=0)&&validate)
236 {
237 if(!valid_zqt(header.templatepath))
238 {
239 jwin_alert("Error","Invalid Quest Template",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
240 return false;
241 }
242 }
243
244 for(int32_t i=0; i<map_count; i++)
245 {
246 setCurrMap(i);
247 sprintf(tbuf, "%d", i);
248 clearmap(true);
249 }
250
251 setCurrMap(0);
252 return true;
253 }
254
255 bool zmap::reset_templates(bool validate)
256 {
257 //why are we doing this?
258 if(colordata==NULL)
259 {
260 return false;
261 }
262
263 char *deletefilename=(char *)malloc(1);
264 ASSERT(deletefilename);
265 deletefilename[0]=0;
266
267 //int32_t ret;
268 word version, build, dummy, sversion=0;
269 byte dummyc;
270 word dummyw;
271 //int32_t section_size;
272 word temp_map_count;
273 mapscr temp_mapscr;
274 PACKFILE *f=NULL;
275
276 // setPackfilePassword(datapwd);
277 f=open_quest_template(&header, deletefilename, validate);
278 get_version_and_build(f, &version, &build);
279
280 if(!find_section(f, ID_MAPS))
281 {
282 // setPackfilePassword(NULL);
283 return false;
284 }
285
286 //section version info
287 if(!p_igetw(&sversion,f))
288 {
289 return false;
290 }
291
292 if(!p_igetw(&dummy,f))
293 {
294 return false;
295 }
296
297 //section size
298 dword dummy_size;
299 if(!p_igetl(&dummy_size,f))
300 {
301 return false;
302 }
303
304 //finally... section data
305 if(!p_igetw(&temp_map_count,f))
306 {
307 return false;
308 }
309
310 if(version>12)
311 {
312 if(!p_getc(&dummyc,f))
313 return qe_invalid;
314
315 if(!p_getc(&dummyc,f))
316 return qe_invalid;
317
318 if(!p_igetw(&dummyw,f))
319 return qe_invalid;
320
321 if(!p_igetw(&dummyw,f))
322 return qe_invalid;
323
324 if(!p_igetw(&dummyw,f))
325 return qe_invalid;
326
327 if(!p_igetw(&dummyw,f))
328 return qe_invalid;
329
330 if(!p_igetw(&dummyw,f))
331 return qe_invalid;
332
333 if(!p_igetw(&dummyw,f))
334 return qe_invalid;
335
336 if(!p_igetw(&dummyw,f))
337 return qe_invalid;
338
339 if(!p_igetw(&dummyw,f))
340 return qe_invalid;
341
342 if(!p_igetw(&dummyw,f))
343 return qe_invalid;
344
345 if(!p_igetw(&dummyw,f))
346 return qe_invalid;
347
348 if(!p_getc(&dummyc,f))
349 return qe_invalid;
350
351 if(!p_getc(&dummyc,f))
352 return qe_invalid;
353 }
354
355 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
356 {
357 readmapscreen(f, &header, &temp_mapscr, sversion);
358 }
359
360 readmapscreen(f, &header, &TheMaps[128], sversion);
361 readmapscreen(f, &header, &TheMaps[129], sversion);
362
363 for(int32_t i=0; i<(MAPSCRS-(MAPSCRSNORMAL+2)); ++i)
364 {
365 readmapscreen(f, &header, &temp_mapscr, sversion);
366 }
367
368 if(version>12)
369 {
370 if(!p_getc(&dummyc,f))
371 return qe_invalid;
372
373 if(!p_getc(&dummyc,f))
374 return qe_invalid;
375
376 if(!p_igetw(&dummyw,f))
377 return qe_invalid;
378
379 if(!p_igetw(&dummyw,f))
380 return qe_invalid;
381
382 if(!p_igetw(&dummyw,f))
383 return qe_invalid;
384
385 if(!p_igetw(&dummyw,f))
386 return qe_invalid;
387
388 if(!p_igetw(&dummyw,f))
389 return qe_invalid;
390
391 if(!p_igetw(&dummyw,f))
392 return qe_invalid;
393
394 if(!p_igetw(&dummyw,f))
395 return qe_invalid;
396
397 if(!p_igetw(&dummyw,f))
398 return qe_invalid;
399
400 if(!p_igetw(&dummyw,f))
401 return qe_invalid;
402
403 if(!p_igetw(&dummyw,f))
404 return qe_invalid;
405
406 if(!p_getc(&dummyc,f))
407 return qe_invalid;
408
409 if(!p_getc(&dummyc,f))
410 return qe_invalid;
411 }
412
413 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
414 {
415 readmapscreen(f, &header, &temp_mapscr, sversion);
416 }
417
418 readmapscreen(f, &header, &TheMaps[MAPSCRS+128], sversion);
419 readmapscreen(f, &header, &TheMaps[MAPSCRS+129], sversion);
420
421 pack_fclose(f);
422 clear_quest_tmpfile();
423
424 if(deletefilename[0]==0)
425 {
426 delete_file(deletefilename);
427 }
428
429 // setPackfilePassword(NULL);
430
431 return true;
432 }
433
434 bool zmap::clearmap(bool newquest)
435 {
436 if(currmap<map_count)
437 {
438 for(int32_t i=0; i<MAPSCRS-(newquest?0:TEMPLATES); i++)
439 {
440 clearscr(i);
441 }
442
443 setCurrScr(0);
444
445 if(newquest)
446 {
447 if(!reset_templates(false))
448 {
449 jwin_alert("Error","Error resetting","template screens.",NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
450 }
451 }
452 }
453
454 return true;
455 }
456
457 mapscr* zmap::CurrScr()
458 {
459 return screens+currscr;
460 }
461 mapscr* zmap::Scr(int32_t scr)
462 {
463 return screens+scr;
464 }
465 mapscr* zmap::AbsoluteScr(int32_t scr)
466 {
467 if(unsigned(scr) >= MAPSCRS*getMapCount())
468 return nullptr;
469 return &TheMaps[scr];
470 }
471 mapscr* zmap::AbsoluteScr(int32_t map, int32_t scr)
472 {
473 if(map < 0 || map >= getMapCount() || scr < 0 || scr >= MAPSCRS)
474 return nullptr;
475 return AbsoluteScr((map*MAPSCRS)+scr);
476 }
477 void zmap::set_prvscr(int32_t map, int32_t scr)
478 {
479 prvscr=TheMaps[(map*MAPSCRS)+scr];
480
481 for(int32_t i=0; i<6; i++)
482 {
483 if(prvscr.layermap[i]>0)
484 {
485 prvlayers[i]=TheMaps[(prvscr.layermap[i]-1)*MAPSCRS+prvscr.layerscreen[i]];
486 }
487 else
488 prvlayers[i].valid = 0;
489 }
490
491 prv_map=map;
492 prv_scr=scr;
493 }
494 71 int32_t zmap::getCurrMap()
495 {
496 71 return currmap;
497 }
498 bool zmap::isDark()
499 {
500 return (screens[currscr].flags&fDARK)!=0;
501 }
502
503 void zmap::setCurrentView(int32_t map, int32_t scr)
504 {
505 bool change_view = map != Map.getCurrMap() || scr != Map.getCurrScr();
506 if (map != Map.getCurrMap()) Map.setCurrMap(map);
507 if (scr != Map.getCurrScr()) Map.setCurrScr(scr);
508 if (change_view)
509 {
510 refresh(rALL);
511 rebuild_trans_table();
512 }
513 }
514
515 9 void zmap::setCurrMap(int32_t index)
516 {
517 9 int32_t oldmap=currmap;
518 9 optional<int> oldcolor;
519
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(screens)
520 oldcolor = getcolor();
521 9 scrpos[currmap]=currscr;
522 9 currmap=bound(index,0,map_count);
523 9 screens=&TheMaps[currmap*MAPSCRS];
524
525 9 currscr=scrpos[currmap];
526 9 int newcolor = getcolor();
527 9 loadlvlpal(newcolor);
528
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(!oldcolor || *oldcolor != newcolor)
529 9 rebuild_trans_table();
530
531 9 reset_combo_animations2();
532 9 mmap_mark_dirty();
533 9 }
534
535 17 int32_t zmap::getCurrScr()
536 {
537 17 return currscr;
538 }
539 9 void zmap::setCurrScr(int32_t scr)
540 {
541
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 8 times.
9 if(scr==currscr) return;
542
543 8 int32_t oldscr=currscr;
544 8 int32_t oldcolor=getcolor();
545
546
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
8 if(!(screens[currscr].valid&mVALID))
547 {
548 2 oldcolor=-1;
549 2 }
550
551 8 currscr=bound(scr,0,MAPSCRS-1);
552 8 int32_t newcolor=getcolor();
553 8 loadlvlpal(newcolor);
554
555 //setcolor(newcolor);
556
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!(screens[currscr].valid&mVALID))
557 {
558 newcolor=-1;
559 }
560
561
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7 times.
8 if(newcolor!=oldcolor)
562 {
563 7 rebuild_trans_table();
564 7 }
565
566 8 reset_combo_animations2();
567 8 setlayertarget();
568 8 mmap_mark_dirty();
569 9 }
570
571 8 void zmap::setlayertarget()
572 {
573 8 layer_target_map = 0;
574 8 layer_target_multiple = 0;
575
576
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 8 times.
29 for(int32_t m=0; m<getMapCount(); ++m)
577 {
578
2/2
✓ Branch 0 taken 2856 times.
✓ Branch 1 taken 21 times.
2877 for(int32_t s=0; s<MAPSCRS; ++s)
579 {
580 2856 int32_t i=(m*MAPSCRS+s);
581 2856 mapscr *ts=&TheMaps[i];
582
583 // Search through each layer
584
2/2
✓ Branch 0 taken 17136 times.
✓ Branch 1 taken 2856 times.
19992 for(int32_t w=0; w<6; ++w)
585 {
586
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 17134 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
17136 if(ts->layerscreen[w]==currscr && (ts->layermap[w]-1)==currmap)
587 {
588 if(layer_target_map > 0)
589 {
590 layer_target_multiple += 1;
591 continue;
592 }
593
594 layer_target_map = m+1;
595 layer_target_scr = s;
596 }
597 17136 }
598 2856 }
599 21 }
600 8 }
601
602 void zmap::setcolor(int32_t c)
603 {
604 screens[currscr].valid |= mVALID;
605 screens[currscr].color = c;
606
607 if(Color!=c)
608 {
609 Color = c;
610 loadlvlpal(c);
611 rebuild_trans_table();
612 }
613
614 mmap_mark_dirty();
615 }
616
617 25 int32_t zmap::getcolor()
618 {
619
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
25 if(prv_mode)
620 {
621 return prvscr.color;
622 }
623
624 25 return screens[currscr].color;
625 25 }
626
627 void zmap::resetflags()
628 {
629 byte *di=&(screens[currscr].valid);
630
631 for(int32_t i=1; i<48; i++)
632 {
633 *(di+i)=0;
634 }
635 }
636
637 word zmap::tcmbdat(int32_t pos)
638 {
639 return screens[TEMPLATE].data[pos];
640 }
641
642 word zmap::tcmbcset(int32_t pos)
643 {
644 return screens[TEMPLATE].cset[pos];
645 }
646
647 int32_t zmap::tcmbflag(int32_t pos)
648 {
649 return screens[TEMPLATE].sflag[pos];
650 }
651
652 word zmap::tcmbdat2(int32_t pos)
653 {
654 return screens[TEMPLATE2].data[pos];
655 }
656
657 word zmap::tcmbcset2(int32_t pos)
658 {
659 return screens[TEMPLATE2].cset[pos];
660 }
661
662 int32_t zmap::tcmbflag2(int32_t pos)
663 {
664 return screens[TEMPLATE2].sflag[pos];
665 }
666
667 void zmap::TemplateAll()
668 {
669 StartListCommand();
670 for(int32_t i=0; i<128; i++)
671 {
672 if((screens[i].valid&mVALID) && isDungeon(i))
673 DoTemplateCommand(-1, i, currscr);
674 }
675 FinishListCommand();
676 }
677
678 void zmap::Template(int32_t floorcombo, int32_t floorcset, int32_t scr)
679 {
680 if(scr==TEMPLATE)
681 return;
682
683 if(!(screens[scr].valid&mVALID))
684 screens[scr].color=Color;
685
686 screens[scr].valid|=mVALID;
687
688 for(int32_t i=0; i<32; i++)
689 {
690 screens[scr].data[i]=screens[TEMPLATE].data[i];
691 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
692 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
693 }
694
695 for(int32_t i=144; i<176; i++)
696 {
697 screens[scr].data[i]=screens[TEMPLATE].data[i];
698 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
699 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
700 }
701
702 for(int32_t y=2; y<=9; y++)
703 {
704 int32_t j=y<<4;
705 screens[scr].data[j]=screens[TEMPLATE].data[j];
706 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
707 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
708 ++j;
709 screens[scr].data[j]=screens[TEMPLATE].data[j];
710 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
711 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
712 ++j;
713 j+=12;
714 screens[scr].data[j]=screens[TEMPLATE].data[j];
715 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
716 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
717 ++j;
718 screens[scr].data[j]=screens[TEMPLATE].data[j];
719 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
720
721 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
722 ++j;
723 }
724
725 if(floorcombo!=-1)
726 {
727 for(int32_t y=2; y<9; y++)
728 for(int32_t x=2; x<14; x++)
729 {
730 int32_t i=(y<<4)+x;
731 screens[scr].data[i] = floorcombo;
732 screens[scr].cset[i] = floorcset;
733 }
734 }
735
736 for(int32_t i=0; i<4; i++)
737 putdoor(scr,i,screens[scr].door[i]);
738 }
739
740
741 void zmap::clearscr(int32_t scr)
742 {
743 screens[scr].zero_memory();
744 screens[scr].valid=mVERSION;
745 for(int q = 0; q < 6; ++q)
746 {
747 auto layer = map_autolayers[currmap*6+q];
748 screens[scr].layermap[q] = layer;
749 screens[scr].layerscreen[q] = layer ? scr : 0;
750 }
751 mmap_mark_dirty();
752 }
753
754 const char *loaderror[] =
755 {
756
757 "OK","File not found","Incomplete data",
758 "Invalid version","Invalid file"
759
760 };
761
762 int32_t zmap::load(const char *path)
763 {
764 PACKFILE *f=pack_fopen_password(path,F_READ, "");
765
766 if(!f)
767 return 1;
768
769
770 int16_t version;
771 byte build;
772
773 //get the version
774 if(!p_igetw(&version,f))
775 {
776 goto file_error;
777 }
778
779 //get the build
780 if(!p_getc(&build,f))
781 {
782 goto file_error;
783 }
784
785 for(int32_t i=0; i<MAPSCRS; i++)
786 {
787 mapscr tmpimportscr;
788 tmpimportscr.zero_memory();
789 if(readmapscreen(f,&header,&tmpimportscr,version)==qe_invalid)
790 {
791 al_trace("failed zmap::load\n");
792 goto file_error;
793 }
794
795 switch(ImportMapBias)
796 {
797 case 0:
798 *(screens+i) = tmpimportscr;
799 break;
800
801 case 1:
802 if(!(screens[i].valid&mVALID))
803 {
804 *(screens+i) = tmpimportscr;
805 }
806 break;
807
808 case 2:
809 if(tmpimportscr.valid&mVALID)
810 {
811 *(screens+i) = tmpimportscr;
812 }
813 break;
814 }
815 }
816
817
818 pack_fclose(f);
819
820 setCurrScr(0);
821 mmap_mark_dirty();
822 return 0;
823
824 file_error:
825 pack_fclose(f);
826 clearmap(false);
827 return 2;
828 }
829
830 int32_t zmap::save(const char *path)
831 {
832 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
833
834 if(!f)
835 return 1;
836
837 if(!p_iputw(V_MAPS,f))
838 {
839 pack_fclose(f);
840 return 3;
841 }
842
843 // This was the "build number", but that's totally useless here. Keep this junk byte
844 // so as not to totally break exports between ZC versions.
845 if(!p_putc(0,f))
846 {
847 pack_fclose(f);
848 return 3;
849 }
850
851 for(int32_t i=0; i<MAPSCRS; i++)
852 {
853 if(writemapscreen(f,this->getCurrMap(),i) == qe_invalid)
854 {
855 pack_fclose(f);
856 return 2;
857 }
858 }
859
860 pack_fclose(f);
861 return 0;
862 }
863
864
865 bool zmap::ishookshottable(int32_t bx, int32_t by, int32_t i)
866 {
867 // Hookshots can be blocked by solid combos on all 3 ground layers.
868 const newcombo* c = &combobuf[MAPCOMBO(bx,by)];
869
870 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
871 return true;
872 if (c->walk&(1<<i))
873 return false;
874
875 for(int32_t k=0; k<2; k++)
876 {
877 c = &combobuf[MAPCOMBO2(k+1,bx,by)];
878
879 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
880 {
881 return false;
882 }
883 }
884
885 return true;
886 }
887
888 bool zmap::ishookshottable(int32_t map, int32_t screen, int32_t bx, int32_t by, int32_t i)
889 {
890 // Hookshots can be blocked by solid combos on all 3 ground layers.
891 const newcombo* c = &combobuf[MAPCOMBO3(map, screen, -1, bx,by)];
892
893 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
894 return true;
895 if (c->walk&(1<<i))
896 return false;
897
898 for(int32_t k=0; k<2; k++)
899 {
900 c = &combobuf[MAPCOMBO3(map, screen, k+1,bx,by)];
901
902 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
903 {
904 return false;
905 }
906 }
907
908 return true;
909 }
910
911 bool zmap::isstepable(int32_t combo)
912 {
913 // This is kind of odd but it's true to the engine (see maps.cpp)
914 return (combo_class_buf[combobuf[combo].type].ladder_pass);
915 }
916
917 // Returns the letter of the warp combo.
918 int32_t zmap::warpindex(int32_t combo)
919 {
920 switch(combobuf[combo].type)
921 {
922 case cCAVE:
923 case cPIT:
924 case cSTAIR:
925 case cCAVE2:
926 case cSWIMWARP:
927 case cDIVEWARP:
928 case cSWARPA:
929 return 0;
930
931 case cCAVEB:
932 case cPITB:
933 case cSTAIRB:
934 case cCAVE2B:
935 case cSWIMWARPB:
936 case cDIVEWARPB:
937 case cSWARPB:
938 return 1;
939
940 case cCAVEC:
941 case cPITC:
942 case cSTAIRC:
943 case cCAVE2C:
944 case cSWIMWARPC:
945 case cDIVEWARPC:
946 case cSWARPC:
947 return 2;
948
949 case cCAVED:
950 case cPITD:
951 case cSTAIRD:
952 case cCAVE2D:
953 case cSWIMWARPD:
954 case cDIVEWARPD:
955 case cSWARPD:
956 return 3;
957
958 case cPITR:
959 case cSTAIRR:
960 case cSWARPR:
961 return 4;
962 }
963
964 return -1;
965
966 }
967
968 void draw_ladder(BITMAP* dest, int32_t x, int32_t y, int32_t c, bool top = false)
969 {
970 if(top)
971 line(dest,x,y,x+15,y,c);
972 rectfill(dest,x,y,x+3,y+15,c);
973 rectfill(dest,x+12,y,x+15,y+15,c);
974 rectfill(dest,x+4,y+2,x+11,y+5,c);
975 rectfill(dest,x+4,y+10,x+11,y+13,c);
976 }
977
978 void draw_platform(BITMAP* dest, int32_t x, int32_t y, int32_t c)
979 {
980 line(dest,x,y,x+15,y,c);
981 }
982
983 void zmap::put_walkflags_layered(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer)
984 {
985 int32_t cx = COMBOX(pos);
986 int32_t cy = COMBOY(pos);
987
988 newcombo const& c = combobuf[ MAPCOMBO2(layer,cx,cy) ];
989
990 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
991
992 int32_t bridgedetected = 0;
993
994 for(int32_t i=0; i<4; i++)
995 {
996 int32_t tx=((i&2)<<2)+x;
997 int32_t ty=((i&1)<<3)+y;
998 int32_t tx2=((i&2)<<2)+cx;
999 int32_t ty2=((i&1)<<3)+cy;
1000 for (int32_t m = layer; m <= 1; m++)
1001 {
1002 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1003 {
1004 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1005 {
1006 bridgedetected |= (1<<i);
1007 }
1008 }
1009 else
1010 {
1011 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1012 {
1013 bridgedetected |= (1<<i);
1014 }
1015 }
1016 }
1017 if (bridgedetected & (1<<i))
1018 {
1019 if (i >= 3) break;
1020 else continue;
1021 }
1022 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1023 {
1024 for(int32_t k=0; k<8; k+=2)
1025 for(int32_t j=0; j<8; j+=2)
1026 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1027 }
1028 if (!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1029 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1030
1031 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1032 {
1033 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO(cx,cy)) && ishookshottable(cx,cy,i))
1034 {
1035 for(int32_t k=0; k<8; k+=2)
1036 for(int32_t j=0; j<8; j+=2)
1037 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1038 }
1039 else
1040 {
1041 int32_t color = COLOR_SOLID;
1042
1043 if(isstepable(MAPCOMBO(cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || (combo_class_buf[combobuf[MAPCOMBO(cx,cy)].type].water==0 && combo_class_buf[c.type].water==0)))
1044 color=vc(6);
1045 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(cx,cy,i))
1046 color=vc(7);
1047
1048 rectfill(dest,tx,ty,tx+7,ty+7,color);
1049 }
1050 }
1051 }
1052
1053 bridgedetected = 0;
1054 for(int32_t i=0; i<4; i++)
1055 {
1056 int32_t tx2=((i&2)<<2)+cx;
1057 int32_t ty2=((i&1)<<3)+cy;
1058 for (int32_t m = 0; m <= 1; m++)
1059 {
1060 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1061 {
1062 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1063 {
1064 bridgedetected |= (1<<i);
1065 }
1066 }
1067 else
1068 {
1069 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1070 {
1071 bridgedetected |= (1<<i);
1072 }
1073 }
1074 }
1075 }
1076
1077 // Draw damage combos
1078 newcombo const& c0 = combobuf[MAPCOMBO2(-1,cx,cy)];
1079 newcombo const& c1 = combobuf[MAPCOMBO2(0,cx,cy)];
1080 newcombo const& c2 = combobuf[MAPCOMBO2(1,cx,cy)];
1081 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1082 || combo_class_buf[c1.type].modify_hp_amount
1083 || combo_class_buf[c2.type].modify_hp_amount;
1084
1085 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1086
1087 if(dmg)
1088 {
1089 if (bridgedetected <= 0)
1090 {
1091 for(int32_t k=0; k<16; k+=2)
1092 for(int32_t j=0; j<16; j+=2)
1093 if(((k+j)/2)%2)
1094 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1095 }
1096 else
1097 {
1098 for(int32_t i=0; i<4; i++)
1099 {
1100 if (!(bridgedetected & (1<<i)))
1101 {
1102 int32_t tx=((i&2)<<2)+x;
1103 int32_t ty=((i&1)<<3)+y;
1104 for(int32_t k=0; k<8; k+=2)
1105 for(int32_t j=0; j<8; j+=2)
1106 if(((k+j)/2)%2)
1107 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1108 }
1109 }
1110 }
1111 }
1112
1113 if(c.type == cSLOPE)
1114 {
1115 slope_info s(c, x, y);
1116 s.draw(dest, 0, 0, COLOR_SLOPE);
1117 }
1118 auto fl0 = MAPFLAG2(-1,cx,cy);
1119 auto fl1 = MAPFLAG2(0,cx,cy);
1120 auto fl2 = MAPFLAG2(1,cx,cy);
1121 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1122 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1123 {
1124 bool top = false;
1125 if(cy)
1126 {
1127 top = true;
1128 if(combobuf[MAPCOMBO2(-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1129 || combobuf[MAPCOMBO2(0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1130 || combobuf[MAPCOMBO2(1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1131 || MAPFLAG2(-1,cx,cy) == mfSIDEVIEWLADDER
1132 || MAPFLAG2(0,cx,cy) == mfSIDEVIEWLADDER
1133 || MAPFLAG2(1,cx,cy) == mfSIDEVIEWLADDER)
1134 {
1135 top = false;
1136 }
1137 }
1138 draw_ladder(dest,x,y,COLOR_LADDER,top);
1139 }
1140 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1141 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1142 {
1143 draw_platform(dest,x,y,COLOR_LADDER);
1144 }
1145 }
1146
1147 void zmap::put_walkflags_layered_external(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer, int32_t map, int32_t screen)
1148 {
1149 int32_t cx = COMBOX(pos);
1150 int32_t cy = COMBOY(pos);
1151
1152 if (screen < 0) return;
1153 if (map < 0) return;
1154
1155 newcombo const& c = combobuf[MAPCOMBO3(map, screen, layer, pos)];
1156
1157 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1158
1159 int32_t bridgedetected = 0;
1160 for(int32_t i=0; i<4; i++)
1161 {
1162 int32_t tx=((i&2)<<2)+x;
1163 int32_t ty=((i&1)<<3)+y;
1164 int32_t tx2=((i&2)<<2)+cx;
1165 int32_t ty2=((i&1)<<3)+cy;
1166 for (int32_t m = layer; m <= 1; m++)
1167 {
1168 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1169 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1170 {
1171 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1172 {
1173 bridgedetected |= (1<<i);
1174 }
1175 }
1176 else
1177 {
1178 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1179 {
1180 bridgedetected |= (1<<i);
1181 }
1182 }
1183 }
1184 if (bridgedetected & (1<<i))
1185 {
1186 continue;
1187 }
1188 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1189 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1190
1191
1192 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1193 {
1194 for(int32_t k=0; k<8; k+=2)
1195 for(int32_t j=0; j<8; j+=2)
1196 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1197 }
1198 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1199 {
1200 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO3(map, screen, layer, cx,cy)) && ishookshottable(map, screen, cx,cy,i) && layer < 0)
1201 {
1202 for(int32_t k=0; k<8; k+=2)
1203 for(int32_t j=0; j<8; j+=2)
1204 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1205 }
1206 else
1207 {
1208 int32_t color = COLOR_SOLID;
1209
1210 if(isstepable(MAPCOMBO3(map, screen, -1, cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || combo_class_buf[combobuf[MAPCOMBO3(map, screen, -1, cx,cy)].type].water==0))
1211 color=vc(6);
1212 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(map, screen, cx,cy,i))
1213 color=vc(7);
1214
1215 rectfill(dest,tx,ty,tx+7,ty+7,color);
1216 }
1217 }
1218 }
1219
1220 bridgedetected = 0;
1221 for(int32_t i=0; i<4; i++)
1222 {
1223 int32_t tx2=((i&2)<<2)+cx;
1224 int32_t ty2=((i&1)<<3)+cy;
1225 for (int32_t m = 0; m <= 1; m++)
1226 {
1227 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1228 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1229 {
1230 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1231 {
1232 bridgedetected |= (1<<i);
1233 }
1234 }
1235 else
1236 {
1237 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1238 {
1239 bridgedetected |= (1<<i);
1240 }
1241 }
1242 }
1243 }
1244
1245 // Draw damage combos
1246 newcombo const& c0 = combobuf[MAPCOMBO3(map, screen, -1,pos)];
1247 newcombo const& c1 = combobuf[MAPCOMBO3(map, screen, 0,pos)];
1248 newcombo const& c2 = combobuf[MAPCOMBO3(map, screen, 1,pos)];
1249 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1250 || combo_class_buf[c1.type].modify_hp_amount
1251 || combo_class_buf[c2.type].modify_hp_amount;
1252
1253 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1254
1255 if(dmg)
1256 {
1257 if (bridgedetected <= 0)
1258 {
1259 for(int32_t k=0; k<16; k+=2)
1260 for(int32_t j=0; j<16; j+=2)
1261 if(((k+j)/2)%2)
1262 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1263 }
1264 else
1265 {
1266 for(int32_t i=0; i<4; i++)
1267 {
1268 if (!(bridgedetected & (1<<i)))
1269 {
1270 int32_t tx=((i&2)<<2)+x;
1271 int32_t ty=((i&1)<<3)+y;
1272 for(int32_t k=0; k<8; k+=2)
1273 for(int32_t j=0; j<8; j+=2)
1274 if(((k+j)/2)%2)
1275 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1276 }
1277 }
1278 }
1279 }
1280
1281 if(c.type == cSLOPE)
1282 {
1283 slope_info s(c, x, y);
1284 s.draw(dest, 0, 0, COLOR_SLOPE);
1285 }
1286 auto fl0 = MAPFLAG3(map,screen,-1,pos);
1287 auto fl1 = MAPFLAG3(map,screen,0,pos);
1288 auto fl2 = MAPFLAG3(map,screen,1,pos);
1289 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1290 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1291 {
1292 bool top = false;
1293 if(cy)
1294 {
1295 top = true;
1296 if(combobuf[MAPCOMBO3(map,screen,-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1297 || combobuf[MAPCOMBO3(map,screen,0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1298 || combobuf[MAPCOMBO3(map,screen,1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1299 || MAPFLAG3(map,screen,-1,cx,cy-16) == mfSIDEVIEWLADDER
1300 || MAPFLAG3(map,screen,0,cx,cy-16) == mfSIDEVIEWLADDER
1301 || MAPFLAG3(map,screen,1,cx,cy-16) == mfSIDEVIEWLADDER)
1302 {
1303 top = false;
1304 }
1305 }
1306 draw_ladder(dest,x,y,COLOR_LADDER,top);
1307 }
1308 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1309 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1310 {
1311 draw_platform(dest,x,y,COLOR_LADDER);
1312 }
1313 }
1314
1315 void put_walkflags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t layer)
1316 {
1317 const newcombo& c = combobuf[cmbdat];
1318
1319 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1320
1321 for(int32_t i=0; i<4; i++)
1322 {
1323 int32_t tx=((i&2)<<2)+x;
1324 int32_t ty=((i&1)<<3)+y;
1325
1326 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && combo_class_buf[c.type].water!=0)
1327 {
1328 if ((layer==0 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 1) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 2)) && get_qr(qr_DROWN))
1329 {
1330 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1331 //al_trace("water, drown\n");
1332 }
1333 else
1334 {
1335 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1336 //al_trace("water, no drown\n");
1337 }
1338 }
1339
1340
1341 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1342 {
1343 for(int32_t k=0; k<8; k+=2)
1344 for(int32_t j=0; j<8; j+=2)
1345 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1346 }
1347 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1348 {
1349 if(c.type==cLADDERHOOKSHOT)
1350 {
1351 for(int32_t k=0; k<8; k+=2)
1352 for(int32_t j=0; j<8; j+=2)
1353 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1354 }
1355 else
1356 {
1357 int32_t color = COLOR_SOLID;
1358
1359 if(c.type==cLADDERONLY)
1360 color=vc(6);
1361 else if(c.type==cHOOKSHOTONLY)
1362 color=vc(7);
1363
1364 rectfill(dest,tx,ty,tx+7,ty+7,color);
1365 }
1366 }
1367
1368 // Draw damage combos
1369 if(combo_class_buf[c.type].modify_hp_amount != 0)
1370 {
1371 for(int32_t k=0; k<8; k+=2)
1372 for(int32_t j=0; j<8; j+=2)
1373 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(4));
1374 }
1375 }
1376
1377 if(c.type == cSLOPE)
1378 {
1379 slope_info s(c, 0, 0);
1380 zfix const& slope = s.slope();
1381
1382 BITMAP* sub = create_bitmap_ex(8,16,16);
1383 clear_bitmap(sub);
1384 s.draw(sub, 0, 0, COLOR_SLOPE);
1385 masked_blit(sub, dest, 0, 0, x, y, 16, 16);
1386 destroy_bitmap(sub);
1387 }
1388 if(c.flag == mfSIDEVIEWLADDER)
1389 {
1390 draw_ladder(dest,x,y,COLOR_LADDER);
1391 }
1392 else if(c.flag == mfSIDEVIEWPLATFORM)
1393 {
1394 draw_platform(dest,x,y,COLOR_LADDER);
1395 }
1396 }
1397
1398 void put_flag(BITMAP* dest, int32_t x, int32_t y, int32_t flag)
1399 {
1400 rectfill(dest,x,y,x+15,y+15,vc(flag&15));
1401 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(flag&15)),-1,"%d",flag);
1402 }
1403 void put_flags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1404 {
1405
1406 newcombo const& c = combobuf[cmbdat];
1407
1408 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1409 {
1410 // rectfill(dest,x,y,x+15,y+15,vc(cmbdat>>10+1));
1411 // text_mode(-1);
1412 // textprintf_ex(dest,get_zc_font(font_sfont),x+1,y+1,(sflag)==0x7800?vc(0):vc(15),-1,"%d",sflag);
1413 if(sflag)
1414 {
1415 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1416 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1417 }
1418
1419 if(c.flag)
1420 {
1421 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1422 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1423 }
1424 }
1425
1426 if(flags&cCSET)
1427 {
1428 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1429 // text_mode(inv?vc(15):vc(0));
1430 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1431 }
1432 else if(flags&cCTYPE)
1433 {
1434 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1435 // text_mode(inv?vc(15):vc(0));
1436 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1437 }
1438 }
1439
1440 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag,int32_t scale)
1441 {
1442 bool repos = combotile_override_x < 0 && combotile_override_y < 0;
1443
1444 BITMAP* b = create_bitmap_ex(8,scale*16,scale*16);
1445 if(repos)
1446 {
1447 combotile_override_x = x+(8*(scale-1));
1448 combotile_override_y = y+(8*(scale-1));
1449 }
1450 put_combo(b,0,0,cmbdat,cset,flags,sflag);
1451 if(repos) combotile_override_x = combotile_override_y = -1;
1452 masked_stretch_blit(b,dest,0,0,16,16,x,y,16*scale,16*scale);
1453 destroy_bitmap(b);
1454 }
1455 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1456 {
1457 static newcombo nilcombo;
1458 nilcombo.tile = 0;
1459
1460 newcombo const& c = cmbdat < MAXCOMBOS ? combobuf[cmbdat] : nilcombo;
1461
1462 if(c.tile==0)
1463 {
1464 rectfill(dest,x,y,x+15,y+15,vc(0));
1465 rectfill(dest,x+3,y+3,x+12,y+12,vc(4));
1466 return;
1467 }
1468
1469 putcombo(dest,x,y,cmbdat,cset);
1470
1471 /* moved to put_walkflags
1472 for(int32_t i=0; i<4; i++) {
1473
1474 int32_t tx=((i&2)<<2)+x;
1475 int32_t ty=((i&1)<<3)+y;
1476 if((flags&cWALK) && (c.walk&(1<<i)))
1477 rectfill(dest,tx,ty,tx+7,ty+7,COLOR_SOLID);
1478 }
1479 */
1480
1481 // if((flags&cFLAGS)&&(cmbdat&0xF800))
1482 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1483 {
1484 // rectfill(dest,x,y,x+15,y+15,vc(cmbdat>>10+1));
1485 // text_mode(-1);
1486 // textprintf_ex(dest,get_zc_font(font_sfont),x+1,y+1,(sflag)==0x7800?vc(0):vc(15),-1,"%d",sflag);
1487 if(sflag)
1488 {
1489 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1490 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1491 }
1492
1493 if(combobuf[cmbdat].flag)
1494 {
1495 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1496 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1497 }
1498 }
1499
1500 if(flags&cWALK)
1501 {
1502 put_walkflags(dest,x,y,cmbdat,0);
1503 }
1504
1505 if(flags&cCSET)
1506 {
1507 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1508 // text_mode(inv?vc(15):vc(0));
1509 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1510 }
1511 else if(flags&cCTYPE)
1512 {
1513 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1514 // text_mode(inv?vc(15):vc(0));
1515 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1516 }
1517 }
1518 void put_engraving(BITMAP* dest, int32_t x, int32_t y, int32_t slot, int32_t scale)
1519 {
1520 auto blitx = 1 + (slot % 16) * 17;
1521 auto blity = 1 + (slot / 16) * 17;
1522 masked_stretch_blit((BITMAP*)zcdata[BMP_ENGRAVINGS].dat, dest, blitx, blity, 16, 16, x, y, 16 * scale, 16 * scale);
1523 }
1524
1525
1526 void copy_mapscr(mapscr *dest, const mapscr *src)
1527 {
1528 if(!dest || !src) return;
1529 *dest = *src;
1530 }
1531
1532 void zmap::put_door(BITMAP *dest,int32_t pos,int32_t side,int32_t type,int32_t xofs,int32_t yofs,bool ignorepos, int32_t scr)
1533 {
1534 int32_t x=0,y=0;
1535 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1536
1537 switch(side)
1538 {
1539 case up:
1540 case down:
1541 x=((pos&15)<<4)+xofs;
1542 y=(ignorepos?0:(pos&0xF0))+yofs;
1543 break;
1544
1545 case left:
1546 case right:
1547 x=(ignorepos?0:((pos&15)<<4))+xofs;
1548 y=(pos&0xF0)+yofs;
1549 break;
1550 }
1551
1552 switch(type)
1553 {
1554 case dt_lock:
1555 case dt_shut:
1556 case dt_boss:
1557 case dt_bomb:
1558 switch(side)
1559 {
1560 case up:
1561 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][0],
1562 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][0],0,0);
1563 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][1],
1564 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][1],0,0);
1565 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][2],
1566 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][2],0,0);
1567 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][3],
1568 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][3],0,0);
1569 break;
1570
1571 case down:
1572 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][0],
1573 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][0],0,0);
1574 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][1],
1575 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][1],0,0);
1576 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][2],
1577 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][2],0,0);
1578 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][3],
1579 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][3],0,0);
1580 break;
1581
1582 case left:
1583 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][0],
1584 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][0],0,0);
1585 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][2],
1586 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][2],0,0);
1587 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][4],
1588 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][4],0,0);
1589
1590 if(x+16 >= dest->w)
1591 break;
1592
1593 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][1],
1594 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][1],0,0);
1595 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][3],
1596 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][3],0,0);
1597 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][5],
1598 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][5],0,0);
1599 break;
1600
1601 case right:
1602
1603 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][1],
1604 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][1],0,0);
1605 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][3],
1606 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][3],0,0);
1607 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][5],
1608 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][5],0,0);
1609
1610 if(x+16 <= 0)
1611 break;
1612
1613 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][0],
1614 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][0],0,0);
1615 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][2],
1616 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][2],0,0);
1617 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][4],
1618 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][4],0,0);
1619 break;
1620 }
1621
1622 break;
1623
1624 case dt_pass:
1625 case dt_wall:
1626 case dt_walk:
1627 default:
1628 break;
1629 }
1630 }
1631
1632 void zmap::over_door(BITMAP *dest,int32_t pos,int32_t side,int32_t xofs,int32_t yofs,bool, int32_t scr)
1633 {
1634 int32_t x=((pos&15)<<4)+xofs;
1635 int32_t y=(pos&0xF0)+yofs;
1636 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1637
1638
1639 switch(side)
1640 {
1641 case up:
1642 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0]!=0)
1643 {
1644 overcombo(dest,x,y,
1645 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0],
1646 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[0]);
1647 }
1648
1649 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1]!=0)
1650 {
1651 overcombo(dest,x+16,y,
1652 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1],
1653
1654 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[1]);
1655 }
1656
1657 break;
1658
1659 case down:
1660 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0]!=0)
1661 {
1662 overcombo(dest,x,y,
1663 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0],
1664 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[0]);
1665 }
1666
1667 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1]!=0)
1668 {
1669 overcombo(dest,x+16,y,
1670 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1],
1671 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[1]);
1672 }
1673
1674 break;
1675
1676 case left:
1677 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0]!=0)
1678 {
1679 overcombo(dest,x,y,
1680 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0],
1681 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[0]);
1682 }
1683
1684 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1]!=0)
1685 {
1686 overcombo(dest,x,y+16,
1687 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1],
1688 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[1]);
1689 }
1690
1691 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2]!=0)
1692 {
1693 overcombo(dest,x,y+32,
1694 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2],
1695 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[2]);
1696 }
1697
1698 break;
1699
1700 case right:
1701 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0]!=0)
1702 {
1703 overcombo(dest,x,y,
1704 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0],
1705 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[0]);
1706 }
1707
1708 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1]!=0)
1709 {
1710 overcombo(dest,x,y+16,
1711
1712 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1],
1713 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[1]);
1714 }
1715
1716 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2]!=0)
1717 {
1718 overcombo(dest,x,y+32,
1719 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2],
1720 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[2]);
1721 }
1722
1723 break;
1724 }
1725 }
1726
1727 bool zmap::misaligned(int32_t map, int32_t scr, int32_t i, int32_t dir)
1728 {
1729 word cmbcheck1, cmbcheck2;
1730 newcombo combocheck1, combocheck2;
1731 combocheck1 = combobuf[0];
1732 combocheck2 = combobuf[0];
1733 combocheck1.walk = 0;
1734 combocheck2.walk = 0;
1735
1736 int32_t layermap, layerscreen;
1737
1738 switch(dir)
1739 {
1740 case up:
1741 {
1742 if(i>15) //not top row of combos
1743 {
1744 return false;
1745 }
1746
1747 if(scr<16) //top row of screens
1748 {
1749 return false;
1750
1751 }
1752
1753 //check main screen
1754 cmbcheck1 = vbound(AbsoluteScr(map, scr)->data[i], 0, MAXCOMBOS-1);
1755 cmbcheck2 = vbound(AbsoluteScr(map, scr-16)->data[i+160], 0, MAXCOMBOS-1);
1756 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1757 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1758
1759 //check layer 1
1760 layermap=AbsoluteScr(map, scr)->layermap[0]-1;
1761
1762 if(layermap>-1 && layermap<map_count)
1763 {
1764 layerscreen=AbsoluteScr(map, scr)->layerscreen[0];
1765 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1766 if (combobuf[cmbcheck1].type == cBRIDGE)
1767 {
1768 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1769 {
1770 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1771 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1772 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1773 }
1774 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1775 }
1776 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1777 }
1778
1779 layermap=AbsoluteScr(map, scr-16)->layermap[0]-1;
1780
1781 if(layermap>-1 && layermap<map_count)
1782 {
1783 layerscreen=AbsoluteScr(map, scr-16)->layerscreen[0];
1784 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1785 if (combobuf[cmbcheck2].type == cBRIDGE)
1786 {
1787 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1788 {
1789 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1790 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1791 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1792 }
1793 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1794 }
1795 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1796 }
1797
1798 //check layer 2
1799 layermap=AbsoluteScr(map, scr)->layermap[1]-1;
1800
1801 if(layermap>-1 && layermap<map_count)
1802 {
1803 layerscreen=AbsoluteScr(map, scr)->layerscreen[1];
1804
1805 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1806 if (combobuf[cmbcheck2].type == cBRIDGE)
1807 {
1808 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1809 {
1810 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1811 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1812 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1813 }
1814 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1815 }
1816 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1817 }
1818
1819 layermap=AbsoluteScr(map, scr-16)->layermap[1]-1;
1820
1821 if(layermap>-1 && layermap<map_count)
1822 {
1823 layerscreen=AbsoluteScr(map, scr-16)->layerscreen[1];
1824 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1825 if (combobuf[cmbcheck2].type == cBRIDGE)
1826 {
1827 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1828 {
1829 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1830 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1831 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1832 }
1833 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1834 }
1835 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1836 }
1837
1838 if(((combocheck1.walk&5)*2)!=(combocheck2.walk&10))
1839 {
1840 return true;
1841 }
1842
1843 break;
1844 }
1845 case down:
1846 {
1847 if(i<160) //not bottom row of combos
1848 {
1849 return false;
1850 }
1851
1852 if(scr>111) //bottom row of screens
1853 {
1854 return false;
1855 }
1856
1857 //check main screen
1858 cmbcheck1 = vbound(AbsoluteScr(map, scr)->data[i], 0, MAXCOMBOS-1);
1859 cmbcheck2 = vbound(AbsoluteScr(map, scr+16)->data[i-160], 0, MAXCOMBOS-1);
1860 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1861 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1862
1863
1864 //check layer 1
1865 layermap=AbsoluteScr(map, scr)->layermap[0]-1;
1866
1867 if(layermap>-1 && layermap<map_count)
1868 {
1869 layerscreen=AbsoluteScr(map, scr)->layerscreen[0];
1870 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1871 if (combobuf[cmbcheck1].type == cBRIDGE)
1872 {
1873 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1874 {
1875 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1876 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1877 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1878 }
1879 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1880 }
1881 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1882 }
1883
1884 layermap=AbsoluteScr(map, scr+16)->layermap[0]-1;
1885
1886 if(layermap>-1 && layermap<map_count)
1887 {
1888 layerscreen=AbsoluteScr(map, scr+16)->layerscreen[0];
1889 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1890 if (combobuf[cmbcheck2].type == cBRIDGE)
1891 {
1892 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1893 {
1894 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1895 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1896 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1897 }
1898 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1899 }
1900 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1901 }
1902
1903 //check layer 2
1904 layermap=AbsoluteScr(map, scr)->layermap[1]-1;
1905
1906 if(layermap>-1 && layermap<map_count)
1907 {
1908 layerscreen=AbsoluteScr(map, scr)->layerscreen[1];
1909 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1910 if (combobuf[cmbcheck1].type == cBRIDGE)
1911 {
1912 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1913 {
1914 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1915 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1916 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1917 }
1918 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1919 }
1920 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1921 }
1922
1923 layermap=AbsoluteScr(map, scr+16)->layermap[1]-1;
1924
1925 if(layermap>-1 && layermap<map_count)
1926 {
1927 layerscreen=AbsoluteScr(map, scr+16)->layerscreen[1];
1928 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1929 if (combobuf[cmbcheck2].type == cBRIDGE)
1930 {
1931 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1932 {
1933 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1934 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1935 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1936 }
1937 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1938 }
1939 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1940 }
1941
1942 if((combocheck1.walk&10)!=((combocheck2.walk&5)*2))
1943 {
1944 return true;
1945 }
1946
1947 break;
1948 }
1949 case left:
1950 {
1951 if((i&0xF)!=0) //not left column of combos
1952 {
1953 return false;
1954 }
1955
1956 if((scr&0xF)==0) //left column of screens
1957 {
1958 return false;
1959 }
1960
1961 //check main screen
1962 cmbcheck1 = AbsoluteScr(map, scr)->data[i];
1963 cmbcheck2 = AbsoluteScr(map, scr-1)->data[i+15];
1964 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1965 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1966
1967 //check layer 1
1968 layermap=AbsoluteScr(map, scr)->layermap[0]-1;
1969
1970 if(layermap>-1 && layermap<map_count)
1971 {
1972 layerscreen=AbsoluteScr(map, scr)->layerscreen[0];
1973 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1974 if (combobuf[cmbcheck1].type == cBRIDGE)
1975 {
1976 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1977 {
1978 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1979 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1980 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1981 }
1982 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1983 }
1984 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1985 }
1986
1987 layermap=AbsoluteScr(map, scr-1)->layermap[0]-1;
1988
1989 if(layermap>-1 && layermap<map_count)
1990 {
1991 layerscreen=AbsoluteScr(map, scr-1)->layerscreen[0];
1992 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
1993 if (combobuf[cmbcheck2].type == cBRIDGE)
1994 {
1995 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1996 {
1997 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1998 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1999 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2000 }
2001 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2002 }
2003 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2004 }
2005
2006 //check layer 2
2007 layermap=AbsoluteScr(map, scr)->layermap[1]-1;
2008
2009 if(layermap>-1 && layermap<map_count)
2010 {
2011 layerscreen=AbsoluteScr(map, scr)->layerscreen[1];
2012 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2013 if (combobuf[cmbcheck1].type == cBRIDGE)
2014 {
2015 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2016 {
2017 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2018 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2019 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2020 }
2021 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2022 }
2023 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2024 }
2025
2026 layermap=AbsoluteScr(map, scr-1)->layermap[1]-1;
2027
2028 if(layermap>-1 && layermap<map_count)
2029 {
2030 layerscreen=AbsoluteScr(map, scr-1)->layerscreen[1];
2031 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2032 if (combobuf[cmbcheck2].type == cBRIDGE)
2033 {
2034 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2035 {
2036 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2037 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2038 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2039 }
2040 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2041 }
2042 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2043 }
2044
2045 if(((combocheck1.walk&3)*4)!=(combocheck2.walk&12))
2046 {
2047 return true;
2048 }
2049
2050 break;
2051 }
2052 case right:
2053 {
2054 if((i&0xF)!=15) //not right column of combos
2055 {
2056 return false;
2057 }
2058
2059 if((scr&0xF)==15) //right column of screens
2060 {
2061 return false;
2062 }
2063
2064 //check main screen
2065 cmbcheck1 = AbsoluteScr(map, scr)->data[i];
2066 cmbcheck2 = AbsoluteScr(map, scr+1)->data[i-15];
2067 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2068 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2069
2070 //check layer 1
2071 layermap=AbsoluteScr(map, scr)->layermap[0]-1;
2072
2073 if(layermap>-1 && layermap<map_count)
2074 {
2075 layerscreen=AbsoluteScr(map, scr)->layerscreen[0];
2076 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2077 if (combobuf[cmbcheck1].type == cBRIDGE)
2078 {
2079 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2080 {
2081 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2082 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2083 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2084 }
2085 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2086 }
2087 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2088 }
2089
2090 layermap=AbsoluteScr(map, scr+1)->layermap[0]-1;
2091
2092 if(layermap>-1 && layermap<map_count)
2093 {
2094 layerscreen=AbsoluteScr(map, scr+1)->layerscreen[0];
2095 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2096 if (combobuf[cmbcheck2].type == cBRIDGE)
2097 {
2098 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2099 {
2100 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2101 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2102 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2103 }
2104 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2105 }
2106 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2107 }
2108
2109 //check layer 2
2110 layermap=AbsoluteScr(map, scr)->layermap[1]-1;
2111
2112 if(layermap>-1 && layermap<map_count)
2113 {
2114 layerscreen=AbsoluteScr(map, scr)->layerscreen[1];
2115 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2116 if (combobuf[cmbcheck1].type == cBRIDGE)
2117 {
2118 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2119 {
2120 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2121 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2122 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2123 }
2124 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2125 }
2126 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2127 }
2128
2129 layermap=AbsoluteScr(map, scr+1)->layermap[1]-1;
2130
2131 if(layermap>-1 && layermap<map_count)
2132 {
2133 layerscreen=AbsoluteScr(map, scr+1)->layerscreen[1];
2134
2135 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2136 if (combobuf[cmbcheck2].type == cBRIDGE)
2137 {
2138 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2139 {
2140 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2141 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2142 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2143 }
2144 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2145 }
2146 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2147 }
2148
2149 if((combocheck1.walk&12)!=((combocheck2.walk&3)*4))
2150 {
2151 return true;
2152 }
2153
2154 break;
2155 }
2156 }
2157
2158 return false;
2159 }
2160
2161 void zmap::check_alignments(BITMAP* dest,int32_t x,int32_t y,int32_t scr)
2162 {
2163 int32_t checkcombo;
2164
2165 if(alignment_arrow_timer>31)
2166 {
2167 if(scr<0)
2168 {
2169 scr=currscr;
2170 }
2171
2172 if((scr<128)) //do the misalignment arrows
2173 {
2174 for(checkcombo=1; checkcombo<15; checkcombo++) //check the top row (except the corners)
2175 {
2176 if(misaligned(currmap, scr, checkcombo, up))
2177 {
2178 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2179 }
2180 }
2181
2182 for(checkcombo=161; checkcombo<175; checkcombo++) //check the top row (except the corners)
2183 {
2184 if(misaligned(currmap, scr, checkcombo, down))
2185 {
2186 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2187 }
2188 }
2189
2190 for(checkcombo=16; checkcombo<160; checkcombo+=16) //check the left side (except the corners)
2191 {
2192 if(misaligned(currmap, scr, checkcombo, left))
2193 {
2194 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2195 }
2196 }
2197
2198 for(checkcombo=31; checkcombo<175; checkcombo+=16) //check the right side (except the corners)
2199 {
2200 if(misaligned(currmap, scr, checkcombo, right))
2201 {
2202 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2203 }
2204 }
2205
2206 int32_t tempalign;
2207
2208 //check top left corner
2209 checkcombo=0;
2210 tempalign=0;
2211 tempalign+=(misaligned(currmap, scr, checkcombo, up))?1:0;
2212 tempalign+=(misaligned(currmap, scr, checkcombo, left))?2:0;
2213
2214 switch(tempalign)
2215 {
2216 case 0:
2217 break;
2218
2219 case 1: //up
2220 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2221 break;
2222
2223 case 2: //left
2224 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2225 break;
2226
2227 case 3: //up-left
2228 masked_blit(arrow_bmp[4],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2229 break;
2230 }
2231
2232 //check top right corner
2233 checkcombo=15;
2234 tempalign=0;
2235 tempalign+=(misaligned(currmap, scr, checkcombo, up))?1:0;
2236 tempalign+=(misaligned(currmap, scr, checkcombo, right))?2:0;
2237
2238 switch(tempalign)
2239 {
2240 case 0:
2241 break;
2242
2243 case 1: //up
2244 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2245 break;
2246
2247 case 2: //right
2248 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2249 break;
2250
2251 case 3: //up-right
2252 masked_blit(arrow_bmp[5],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2253 break;
2254 }
2255
2256 //check bottom left corner
2257 checkcombo=160;
2258 tempalign=0;
2259 tempalign+=(misaligned(currmap, scr, checkcombo, down))?1:0;
2260 tempalign+=(misaligned(currmap, scr, checkcombo, left))?2:0;
2261
2262 switch(tempalign)
2263 {
2264 case 0:
2265 break;
2266
2267 case 1: //down
2268 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2269 break;
2270
2271 case 2: //left
2272 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2273 break;
2274
2275 case 3: //down-left
2276 masked_blit(arrow_bmp[6],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2277 break;
2278 }
2279
2280 //check bottom right corner
2281
2282 checkcombo=175;
2283 tempalign=0;
2284 tempalign+=(misaligned(currmap, scr, checkcombo, down))?1:0;
2285 tempalign+=(misaligned(currmap, scr, checkcombo, right))?2:0;
2286
2287 switch(tempalign)
2288 {
2289 case 0:
2290 break;
2291
2292 case 1: //down
2293 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2294 break;
2295
2296 case 2: //right
2297 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2298 break;
2299
2300 case 3: //down-right
2301 masked_blit(arrow_bmp[7],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2302 break;
2303 }
2304 }
2305 }
2306 }
2307
2308 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2309 {
2310 return MAPCOMBO3(map, screen, layer, COMBOPOS(x,y));
2311 }
2312
2313 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2314 {
2315 if (map < 0 || screen < 0) return 0;
2316
2317 if(pos>175 || pos < 0)
2318 return 0;
2319
2320 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2321
2322 if(m->valid==0) return 0;
2323
2324 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2325
2326 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2327
2328 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2329
2330 if(scr->valid==0) return 0;
2331
2332 return scr->data[pos]; // entire combo code
2333 }
2334
2335 // Takes array index layer num., not actual layer num.
2336 int32_t zmap::MAPCOMBO2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2337 {
2338 if(lyr<=-1) return MAPCOMBO(x,y,map,scr);
2339
2340 if(map<0)
2341 map=currmap;
2342
2343 if(scr<0)
2344 scr=currscr;
2345
2346 mapscr *screen1;
2347
2348 if(prv_mode)
2349 {
2350 screen1=get_prvscr();
2351 }
2352 else
2353 {
2354 screen1=AbsoluteScr(currmap,currscr);
2355 }
2356
2357 int32_t layermap;
2358 layermap=screen1->layermap[lyr]-1;
2359
2360 if(layermap<0 || layermap >= map_count) return 0;
2361
2362 mapscr *layer;
2363
2364 if(prv_mode)
2365 layer = &prvlayers[lyr];
2366 else
2367 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2368
2369 int32_t combo = COMBOPOS(x,y);
2370
2371 if(combo>175 || combo < 0)
2372 return 0;
2373
2374 return layer->data[combo];
2375 }
2376
2377 int32_t zmap::MAPCOMBO(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2378 {
2379 if(map<0)
2380 map=currmap;
2381
2382 if(scr<0)
2383 scr=currscr;
2384
2385 mapscr *screen1;
2386
2387 if(prv_mode)
2388 {
2389 screen1=get_prvscr();
2390 }
2391 else
2392 {
2393 screen1=AbsoluteScr(currmap,currscr);
2394 }
2395
2396 x = vbound(x, 0, 16*16);
2397 y = vbound(y, 0, 11*16);
2398 int32_t combo = COMBOPOS(x,y);
2399
2400 if(combo>175 || combo < 0)
2401 return 0;
2402
2403 return screen1->data[combo];
2404 }
2405
2406 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2407 {
2408 return MAPFLAG3(map, screen, layer, COMBOPOS(x,y));
2409 }
2410
2411 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2412 {
2413 if (map < 0 || screen < 0) return 0;
2414
2415 if(pos>175 || pos < 0)
2416 return 0;
2417
2418 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2419
2420 if(m->valid==0) return 0;
2421
2422 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2423
2424 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2425
2426 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2427
2428 if(scr->valid==0) return 0;
2429
2430 return scr->sflag[pos]; // entire combo code
2431 }
2432
2433 int32_t zmap::MAPFLAG2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2434 {
2435 if(lyr<=-1) return MAPFLAG(x,y,map,scr);
2436
2437 if(map<0)
2438 map=currmap;
2439
2440 if(scr<0)
2441 scr=currscr;
2442
2443 mapscr *screen1;
2444
2445 if(prv_mode)
2446 {
2447 screen1=get_prvscr();
2448 }
2449 else
2450 {
2451 screen1=AbsoluteScr(currmap,currscr);
2452 }
2453
2454 int32_t layermap;
2455 layermap=screen1->layermap[lyr]-1;
2456
2457 if(layermap<0 || layermap >= map_count) return 0;
2458
2459 mapscr *layer;
2460
2461 if(prv_mode)
2462 layer = &prvlayers[lyr];
2463 else
2464 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2465
2466 int32_t combo = COMBOPOS(x,y);
2467
2468 if(combo>175 || combo < 0)
2469 return 0;
2470
2471 return layer->sflag[combo];
2472 }
2473
2474 int32_t zmap::MAPFLAG(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2475 {
2476 if(map<0)
2477 map=currmap;
2478
2479 if(scr<0)
2480 scr=currscr;
2481
2482 mapscr *screen1;
2483
2484 if(prv_mode)
2485 {
2486 screen1=get_prvscr();
2487 }
2488 else
2489 {
2490 screen1=AbsoluteScr(currmap,currscr);
2491 }
2492
2493 x = vbound(x, 0, 16*16);
2494 y = vbound(y, 0, 11*16);
2495 int32_t combo = COMBOPOS(x,y);
2496
2497 if(combo>175 || combo < 0)
2498 return 0;
2499
2500 return screen1->sflag[combo];
2501 }
2502
2503 void zmap::draw_darkness(BITMAP* dest, BITMAP* transdest)
2504 {
2505 mapscr *layers[7];
2506 mapscr *basescr;
2507 if(prv_mode)
2508 {
2509 layers[0] = &prvscr;
2510 basescr = layers[0];
2511 for(auto q = 1; q < 7; ++q)
2512 {
2513 if(prvlayers[q-1].valid)
2514 layers[q] = &(prvlayers[q-1]);
2515 else layers[q] = NULL;
2516 }
2517 }
2518 else
2519 {
2520 layers[0] = AbsoluteScr(currmap, currscr);
2521 basescr = layers[0];
2522 for(auto q = 1; q < 7; ++q)
2523 {
2524 int32_t lmap = basescr->layermap[q-1]-1;
2525 int32_t lscr = basescr->layerscreen[q-1];
2526 if(lmap < 0)
2527 layers[q] = NULL;
2528 else layers[q] = AbsoluteScr(lmap, lscr);
2529 }
2530 }
2531 for(auto q = 0; q < 7; ++q)
2532 {
2533 if(!layers[q]) continue;
2534 for(auto pos = 0; pos < 176; ++pos)
2535 {
2536 newcombo const& cmb = combobuf[layers[q]->data[pos]];
2537 if(cmb.type == cTORCH)
2538 do_torch_combo(cmb, COMBOX(pos)+8, COMBOY(pos)+8, dest, transdest);
2539 }
2540 }
2541 word maxffc = basescr->numFFC();
2542 for(auto q = 0; q < maxffc; ++q)
2543 {
2544 newcombo const& cmb = combobuf[basescr->ffcs[q].data];
2545 if(cmb.type == cTORCH)
2546 do_torch_combo(cmb, (basescr->ffcs[q].x.getInt())+(basescr->ffEffectWidth(q)/2), (basescr->ffcs[q].y.getInt())+(basescr->ffEffectHeight(q)/2), dest, transdest);
2547 }
2548 }
2549
2550 void drawcombo(BITMAP* dest, int32_t x, int32_t y, int32_t cid, int32_t cset, int32_t flags,
2551 int32_t sflag, bool over = true, bool transp = false, bool dither = false)
2552 {
2553 newcombo const& cmb = combobuf[cid];
2554 if(cmb.animflags & AF_TRANSPARENT) transp = !transp;
2555 if(dither)
2556 {
2557 if (LayerDitherSz == 0)
2558 return;
2559 BITMAP* buf = create_bitmap_ex(8,16,16);
2560 clear_bitmap(buf);
2561 overcombo(buf,0,0,cid,cset);
2562 ditherblit(buf,nullptr,0,dithChecker,LayerDitherSz,x,y);
2563 if(over)
2564 {
2565 if(transp)
2566 {
2567 color_map = &trans_table2;
2568 draw_trans_sprite(dest, buf, x, y);
2569 color_map = &trans_table;
2570 }
2571 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2572 }
2573 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2574 destroy_bitmap(buf);
2575 }
2576 else if(over)
2577 {
2578 if(transp)
2579 overcombotranslucent(dest,x,y,cid,cset,0);
2580 else overcombo(dest,x,y,cid,cset);
2581 }
2582 else put_combo(dest,x,y,cid,cset,flags,sflag);
2583 }
2584 static void _zmap_drawlayer(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool over, bool dither, bool passflag = false)
2585 {
2586 if(!md) return;
2587 for (int32_t i = 0; i < 176; i++)
2588 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, md->data[i], md->cset[i], flags, passflag ? md->sflag[i] : 0, over, trans, dither);
2589 }
2590 static void _zmap_drawlayer_ohead(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool dither)
2591 {
2592 if(!md) return;
2593 for (int32_t i = 0; i < 176; i++)
2594 {
2595 int data = md->data[i];
2596 if(combo_class_buf[combobuf[data].type].overhead)
2597 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, data, md->cset[i], 0, 0, true, trans, dither);
2598 }
2599 }
2600 static mapscr* _zmap_get_lyr_checked(int lyr, mapscr* basescr)
2601 {
2602 if(!LayerMaskInt[lyr])
2603 return nullptr;
2604 if(lyr == 0)
2605 return basescr;
2606 int layermap = basescr->layermap[lyr-1]-1;
2607
2608 if(layermap>-1 && layermap<map_count)
2609 {
2610 int layerscreen = layermap*MAPSCRS+basescr->layerscreen[lyr-1];
2611 return &TheMaps[layerscreen];
2612 }
2613 return nullptr;
2614 }
2615 void zmap::draw(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t map,int32_t scr,int32_t hl_layer)
2616 {
2617 #define HL_LAYER(lyr) (!(NoHighlightLayer0 && hl_layer == 0) && hl_layer > -1 && hl_layer != lyr)
2618 int32_t antiflags=(flags&~cFLAGS)&~cWALK;
2619
2620 if(map<0)
2621 map=currmap;
2622
2623 if(scr<0)
2624 scr=currscr;
2625
2626 mapscr *basescr;
2627 mapscr* layers[7] = {nullptr};
2628
2629 if(prv_mode)
2630 {
2631 hl_layer = -1;
2632 basescr=get_prvscr();
2633 }
2634 else
2635 {
2636 basescr=AbsoluteScr(map,scr);
2637 }
2638 layers[0] = _zmap_get_lyr_checked(0,basescr);
2639 for(int lyr = 1; lyr < 7; ++lyr)
2640 {
2641 layers[lyr] = prv_mode ? ((&prvlayers[lyr-1])->valid ? &prvlayers[lyr - 1] : nullptr)
2642 : _zmap_get_lyr_checked(lyr,basescr);
2643 }
2644
2645 int32_t layermap, layerscreen;
2646 if(CurrentLayer < 1)
2647 layermap = -1;
2648 else
2649 {
2650 layermap=basescr->layermap[CurrentLayer-1]-1;
2651
2652 if(layermap<0)
2653 CurrentLayer=0;
2654 }
2655
2656 if(!(basescr->valid&mVALID))
2657 {
2658 // rectfill(dest,x,y,x+255,y+175,dvc(0+1));
2659 rectfill(dest,x,y,x+255,y+175,vc(1));
2660
2661 if(ShowMisalignments)
2662 {
2663 check_alignments(dest,x,y,scr);
2664 }
2665
2666 return;
2667 }
2668
2669 if(LayerMaskInt[0]==0)
2670 {
2671 byte bgfill = 0;
2672 if (LayerDitherBG > -1)
2673 bgfill = vc(LayerDitherBG);
2674 rectfill(dest,x,y,x+255,y+175,bgfill);
2675 }
2676
2677 resize_mouse_pos=true;
2678 if(XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2679 _zmap_drawlayer(dest, x, y, layers[2], antiflags, false, false, HL_LAYER(2));
2680
2681 if(XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2682 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG), HL_LAYER(3));
2683
2684 _zmap_drawlayer(dest, x, y, layers[0], antiflags, false, (XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG)||XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG)), HL_LAYER(0), true);
2685
2686 _zmap_drawlayer(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, true, HL_LAYER(1));
2687
2688 for(int32_t i=MAXFFCS-1; i>=0; i--)
2689 {
2690 if(basescr->ffcs[i].data)
2691 {
2692 if(!(basescr->ffcs[i].flags&ffCHANGER))
2693 {
2694 if(!(basescr->ffcs[i].flags&ffOVERLAY))
2695 {
2696 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2697 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2698
2699 if(basescr->ffcs[i].flags&ffTRANS)
2700 {
2701 overcomboblocktranslucent(dest, tx, ty, basescr->ffcs[i].data, basescr->ffcs[i].cset,basescr->ffTileWidth(i), basescr->ffTileHeight(i),128);
2702 //overtiletranslucent16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip, 128);
2703 }
2704 else
2705 {
2706 overcomboblock(dest, tx, ty, basescr->ffcs[i].data, basescr->ffcs[i].cset, basescr->ffTileWidth(i), basescr->ffTileHeight(i));
2707 //overtile16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip);
2708 }
2709 }
2710 }
2711 }
2712 }
2713
2714 if(!XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2715 _zmap_drawlayer(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, true, HL_LAYER(2));
2716
2717 int32_t doortype[4];
2718
2719 for(int32_t i=0; i<4; i++)
2720 {
2721 switch(basescr->door[i])
2722 {
2723 case dOPEN:
2724 doortype[i]=dt_pass;
2725 break;
2726
2727 case dLOCKED:
2728 doortype[i]=dt_lock;
2729 break;
2730
2731 case d1WAYSHUTTER:
2732 case dSHUTTER:
2733 doortype[i]=dt_shut;
2734 break;
2735
2736 case dBOSS:
2737 doortype[i]=dt_boss;
2738 break;
2739
2740 case dBOMB:
2741 doortype[i]=dt_bomb;
2742 break;
2743 }
2744 }
2745
2746 switch(basescr->door[up])
2747 {
2748 case dBOMB:
2749 over_door(dest,39,up,x,y,false, scr);
2750 [[fallthrough]];
2751 case dOPEN:
2752 case dLOCKED:
2753 case d1WAYSHUTTER:
2754 case dSHUTTER:
2755 case dBOSS:
2756 put_door(dest,7,up,doortype[up],x,y,false,scr);
2757 break;
2758
2759 case dWALK:
2760 if(get_bit(DoorComboSets[screens[currscr].door_combo_set].flags,df_walktrans))
2761 {
2762 overcombo(dest,((23&15)<<4)+8+x,(23&0xF0)+y,
2763 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[0],
2764 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[0]);
2765 }
2766 else
2767
2768 {
2769 put_combo(dest,((23&15)<<4)+8+x,(23&0xF0)+y,
2770 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[0],
2771 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[0],0,0);
2772 }
2773
2774 break;
2775 }
2776
2777 switch(basescr->door[down])
2778 {
2779 case dBOMB:
2780 over_door(dest,135,down,x,y,false,scr);
2781 [[fallthrough]];
2782 case dOPEN:
2783 case dLOCKED:
2784 case d1WAYSHUTTER:
2785 case dSHUTTER:
2786 case dBOSS:
2787 put_door(dest,151,down,doortype[down],x,y,false,scr);
2788 break;
2789
2790 case dWALK:
2791 if(get_bit(DoorComboSets[screens[currscr].door_combo_set].flags,df_walktrans))
2792 {
2793 overcombo(dest,((151&15)<<4)+8+x,(151&0xF0)+y,
2794 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[1],
2795 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[1]);
2796 }
2797 else
2798 {
2799 put_combo(dest,((151&15)<<4)+8+x,(151&0xF0)+y,
2800 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[1],
2801 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[1],0,0);
2802 }
2803
2804 break;
2805 }
2806
2807 switch(basescr->door[left])
2808 {
2809 case dBOMB:
2810 over_door(dest,66,left,x,y,false,scr);
2811 [[fallthrough]];
2812 case dOPEN:
2813 case dLOCKED:
2814 case d1WAYSHUTTER:
2815 case dSHUTTER:
2816 case dBOSS:
2817 put_door(dest,64,left,doortype[left],x,y,false,scr);
2818 break;
2819
2820 case dWALK:
2821 if(get_bit(DoorComboSets[screens[currscr].door_combo_set].flags,df_walktrans))
2822 {
2823 overcombo(dest,((81&15)<<4)+x,(81&0xF0)+y,
2824 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[2],
2825 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[2]);
2826 }
2827 else
2828 {
2829 put_combo(dest,((81&15)<<4)+x,(81&0xF0)+y,
2830 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[2],
2831 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[2],0,0);
2832 }
2833
2834 break;
2835 }
2836
2837 switch(basescr->door[right])
2838 {
2839
2840 case dBOMB:
2841 over_door(dest,77,right,x,y,false,scr);
2842 [[fallthrough]];
2843 case dOPEN:
2844 case dLOCKED:
2845 case d1WAYSHUTTER:
2846 case dSHUTTER:
2847 case dBOSS:
2848 put_door(dest,78,right,doortype[right],x,y,false,scr);
2849 break;
2850
2851 case dWALK:
2852 if(get_bit(DoorComboSets[screens[currscr].door_combo_set].flags,df_walktrans))
2853 {
2854 overcombo(dest,((94&15)<<4)+x,(94&0xF0)+y,
2855 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[3],
2856 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[3]);
2857 }
2858 else
2859 {
2860 put_combo(dest,((94&15)<<4)+x,(94&0xF0)+y,
2861 DoorComboSets[screens[currscr].door_combo_set].walkthroughcombo[3],
2862 DoorComboSets[screens[currscr].door_combo_set].walkthroughcset[3],0,0);
2863 }
2864
2865 break;
2866 }
2867
2868 if((basescr->hasitem != 0) && !(flags&cNOITEM))
2869 {
2870 frame=0;
2871 putitem2(dest,basescr->itemx+x,basescr->itemy+y+1-(get_qr(qr_NOITEMOFFSET)),basescr->item,lens_hint_item[basescr->item][0],lens_hint_item[basescr->item][1], 0);
2872 }
2873
2874 if(!XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2875 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, true, HL_LAYER(3));
2876 _zmap_drawlayer(dest, x, y, layers[4], antiflags, basescr->layeropacity[4-1]!=255, true, HL_LAYER(4));
2877
2878 _zmap_drawlayer_ohead(dest, x, y, layers[0], antiflags, false, HL_LAYER(0));
2879
2880 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
2881 {
2882 _zmap_drawlayer_ohead(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, HL_LAYER(1));
2883 _zmap_drawlayer_ohead(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, HL_LAYER(2));
2884 }
2885 _zmap_drawlayer(dest, x, y, layers[5], antiflags, basescr->layeropacity[5-1]!=255, true, HL_LAYER(5));
2886
2887 for(int32_t i=MAXFFCS-1; i>=0; i--)
2888 {
2889 if(basescr->ffcs[i].data)
2890 {
2891 if(!(basescr->ffcs[i].flags&ffCHANGER))
2892 {
2893 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2894 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2895
2896 if(basescr->ffcs[i].flags&ffOVERLAY)
2897 {
2898 if(basescr->ffcs[i].flags&ffTRANS)
2899 {
2900 //overtiletranslucent16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip, 128);
2901 overcomboblocktranslucent(dest,tx,ty,basescr->ffcs[i].data, basescr->ffcs[i].cset, basescr->ffTileWidth(i), basescr->ffTileHeight(i),128);
2902 }
2903 else
2904 {
2905 //overtile16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip);
2906 overcomboblock(dest, tx, ty, basescr->ffcs[i].data, basescr->ffcs[i].cset, basescr->ffTileWidth(i), basescr->ffTileHeight(i));
2907 }
2908 }
2909 }
2910 }
2911 }
2912
2913 _zmap_drawlayer(dest, x, y, layers[6], antiflags, basescr->layeropacity[6-1]!=255, true, HL_LAYER(6));
2914
2915 for(int32_t i=MAXFFCS-1; i>=0; i--)
2916 if(basescr->ffcs[i].data)
2917 if(basescr->ffcs[i].flags&ffCHANGER)
2918 putpixel(dest,(basescr->ffcs[i].x.getInt())+x,(basescr->ffcs[i].y.getInt())+y,vc(zc_oldrand()%16));
2919
2920 if(flags&cWALK)
2921 {
2922 if(layers[0])
2923 for(int32_t i=0; i<176; i++)
2924 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[0]->data[i], 0);
2925
2926 for(int32_t k=0; k<2; k++)
2927 {
2928 if(layers[k+1])
2929 for(int32_t i=0; i<176; i++)
2930 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[k+1]->data[i], 0);
2931 }
2932 for(int32_t i=MAXFFCS-1; i>=0; i--)
2933 {
2934 if(auto data = basescr->ffcs[i].data)
2935 {
2936 if(!(basescr->ffcs[i].flags&ffCHANGER))
2937 {
2938 newcombo const& cmb = combobuf[data];
2939 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2940 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2941
2942 if(basescr->ffcs[i].flags&ffSOLID)
2943 {
2944 rectfill(dest, tx, ty, tx + basescr->ffEffectWidth(i) - 1, ty + basescr->ffEffectHeight(i) - 1, COLOR_SOLID);
2945 }
2946
2947 if(cmb.type == cSLOPE)
2948 {
2949 slope_info s(cmb, tx, ty);
2950 s.draw(dest, 0, 0, COLOR_SLOPE);
2951 }
2952 }
2953 }
2954 }
2955 }
2956
2957 if(flags&cFLAGS)
2958 {
2959 if(LayerMaskInt[CurrentLayer]!=0)
2960 {
2961 for(int32_t i=0; i<176; i++)
2962 {
2963 if(CurrentLayer==0)
2964 {
2965 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,basescr->data[i],basescr->cset[i],flags,basescr->sflag[i]);
2966 }
2967 else
2968 {
2969 if(prv_mode)
2970 {
2971 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,prvlayers[CurrentLayer-1].data[i],prvlayers[CurrentLayer-1].cset[i],flags,prvlayers[CurrentLayer-1].sflag[i]);
2972 }
2973 else
2974 {
2975 int32_t _lscr=(basescr->layermap[CurrentLayer-1]-1)*MAPSCRS+basescr->layerscreen[CurrentLayer-1];
2976
2977 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
2978 {
2979 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,
2980 TheMaps[_lscr].data[i],
2981 TheMaps[_lscr].cset[i], flags,
2982 TheMaps[_lscr].sflag[i]);
2983 }
2984 }
2985 }
2986 }
2987 }
2988 }
2989
2990 int32_t dark = basescr->flags&cDARK;
2991
2992 if(dark && !(flags&cNODARK)
2993 && !((Flags&cNEWDARK) && get_qr(qr_NEW_DARKROOM)))
2994 {
2995 for(int32_t j=0; j<80; j++)
2996 {
2997 for(int32_t i=0; i<(80)-j; i++)
2998 {
2999 if(((i^j)&1)==0)
3000 {
3001 putpixel(dest,x+i,y+j,vc(blackout_color));
3002 }
3003 }
3004 }
3005 }
3006
3007 if(ShowMisalignments)
3008 {
3009 check_alignments(dest,x,y,scr);
3010 }
3011
3012 resize_mouse_pos=false;
3013 }
3014
3015 void zmap::drawrow(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3016 {
3017 if(map<0)
3018 map=currmap;
3019
3020 if(scr<0)
3021 scr=currscr;
3022
3023 mapscr* layer=AbsoluteScr(map,scr);
3024 int32_t layermap=0, layerscreen=0;
3025
3026 if(!(layer->valid&mVALID))
3027 {
3028 // rectfill(dest,x,y,x+255,y+15,dvc(0+1));
3029 rectfill(dest,x,y,x+255,y+15,vc(1));
3030 return;
3031 }
3032
3033 int32_t dark = layer->flags&4;
3034
3035 resize_mouse_pos=true;
3036
3037 if(LayerMaskInt[0]==0)
3038 {
3039 rectfill(dest,x,y,x+255,y+15,0);
3040 }
3041
3042 // int32_t cs=2;
3043
3044 for(int32_t k=1; k<3; k++)
3045 {
3046 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3047 {
3048 layermap=layer->layermap[k]-1;
3049
3050 if(layermap>-1 && layermap<map_count)
3051 {
3052 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3053
3054 for(int32_t i=c; i<(c&0xF0)+16; i++)
3055 {
3056 auto data = TheMaps[layerscreen].data[i];
3057 auto cs = TheMaps[layerscreen].cset[i];
3058 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3059 }
3060 }
3061 }
3062 }
3063
3064 if(LayerMaskInt[0]!=0)
3065 {
3066 for(int32_t i=c; i<(c&0xF0)+16; i++)
3067 {
3068 word cmbdat = (i < 176 ? layer->data[i] : 0);
3069 byte cmbcset = (i < 176 ? layer->cset[i] : 0);
3070 int32_t cmbflag = (i < 176 ? layer->sflag[i] : 0);
3071 drawcombo(dest,((i&15)<<4)+x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),
3072 cmbflag,(layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3073 }
3074 }
3075
3076 for(int32_t k=0; k<2; k++)
3077 {
3078 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3079 {
3080 layermap=layer->layermap[k]-1;
3081
3082 if(layermap>-1 && layermap<map_count)
3083 {
3084 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3085
3086 for(int32_t i=c; i<(c&0xF0)+16; i++)
3087 {
3088 auto data = TheMaps[layerscreen].data[i];
3089 auto cs = TheMaps[layerscreen].cset[i];
3090 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3091 }
3092 }
3093 }
3094 }
3095
3096 int32_t doortype[4];
3097
3098 for(int32_t i=0; i<4; i++)
3099 {
3100 switch(layer->door[i])
3101 {
3102 case dOPEN:
3103 doortype[i]=dt_pass;
3104 break;
3105
3106 case dLOCKED:
3107 doortype[i]=dt_lock;
3108 break;
3109
3110 case d1WAYSHUTTER:
3111 case dSHUTTER:
3112 doortype[i]=dt_shut;
3113 break;
3114
3115 case dBOSS:
3116 doortype[i]=dt_boss;
3117 break;
3118
3119 case dBOMB:
3120 doortype[i]=dt_bomb;
3121 break;
3122 }
3123 }
3124
3125 if(c<16)
3126 {
3127 switch(layer->door[up])
3128 {
3129 case dBOMB:
3130 case dOPEN:
3131 case dLOCKED:
3132 case d1WAYSHUTTER:
3133 case dSHUTTER:
3134 case dBOSS:
3135 put_door(dest,7,up,doortype[up],x,y+176,true,scr);
3136 break;
3137 }
3138 }
3139 else if(c>159)
3140 {
3141 switch(layer->door[down])
3142 {
3143 case dBOMB:
3144 case dOPEN:
3145 case dLOCKED:
3146 case d1WAYSHUTTER:
3147 case dSHUTTER:
3148 case dBOSS:
3149 put_door(dest,151,down,doortype[down],x,y-16,true,scr);
3150 break;
3151 }
3152 }
3153
3154 for(int32_t k=2; k<4; k++)
3155 {
3156 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3157 {
3158 layermap=layer->layermap[k]-1;
3159
3160 if(layermap>-1 && layermap<map_count)
3161 {
3162 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3163
3164 for(int32_t i=c; i<(c&0xF0)+16; i++)
3165 {
3166 if(layer->layeropacity[k]<255)
3167 {
3168 overcombotranslucent(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i],layer->layeropacity[k]);
3169 }
3170 else
3171 {
3172 overcombo(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i]);
3173 }
3174 }
3175 }
3176 }
3177 }
3178
3179 //Overhead L0
3180 if(LayerMaskInt[0]!=0)
3181 {
3182 for(int32_t i=c; i<(c&0xF0)+16; i++)
3183 {
3184 int32_t ct1=layer->data[i];
3185 int32_t ct3=combobuf[ct1].type;
3186
3187 if(combo_class_buf[ct3].overhead)
3188 {
3189 drawcombo(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],0,0);
3190 }
3191 }
3192 }
3193
3194 //Overhead L1/2
3195 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3196 {
3197 for(int32_t k = 0; k < 2; ++k)
3198 {
3199 if(LayerMaskInt[k+1]!=0)
3200 {
3201 layermap=layer->layermap[k]-1;
3202
3203 if(layermap>-1 && layermap<map_count)
3204 {
3205 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3206 for(int32_t i=c; i<(c&0xF0)+16; i++)
3207 {
3208 auto data = TheMaps[layerscreen].data[i];
3209 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3210 auto cs = TheMaps[layerscreen].cset[i];
3211 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3212 }
3213 }
3214 }
3215 }
3216 }
3217
3218 for(int32_t k=4; k<6; k++)
3219 {
3220 if(LayerMaskInt[k+1]!=0)
3221 {
3222 layermap=layer->layermap[k]-1;
3223
3224 if(layermap>-1 && layermap<map_count)
3225 {
3226 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3227
3228 for(int32_t i=c; i<(c&0xF0)+16; i++)
3229 {
3230 auto data = TheMaps[layerscreen].data[i];
3231 auto cs = TheMaps[layerscreen].cset[i];
3232 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3233 }
3234 }
3235 }
3236 }
3237
3238 if(flags&cWALK)
3239 {
3240 if(LayerMaskInt[0]!=0)
3241 {
3242 for(int32_t i=c; i<(c&0xF0)+16; i++)
3243 {
3244 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, -1, map,scr);
3245 }
3246 }
3247
3248 for(int32_t k=0; k<2; k++)
3249 {
3250 if(LayerMaskInt[k+1]!=0)
3251 {
3252 for(int32_t i=c; i<(c&0xF0)+16; i++)
3253 {
3254 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, k, map,scr);
3255 }
3256 }
3257 }
3258 }
3259
3260 if(flags&cFLAGS)
3261 {
3262 if(LayerMaskInt[CurrentLayer]!=0)
3263 {
3264 for(int32_t i=c; i<(c&0xF0)+16; i++)
3265 {
3266 if(CurrentLayer==0)
3267 {
3268 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3269 }
3270 else
3271 {
3272 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3273
3274 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3275 {
3276 if(i < 176)
3277 {
3278 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,
3279 TheMaps[_lscr].data[i],
3280 TheMaps[_lscr].cset[i], flags|dark,
3281 TheMaps[_lscr].sflag[i]);
3282 }
3283 else
3284 {
3285 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,0,0, flags|dark,0);
3286 }
3287 }
3288 }
3289 }
3290 }
3291
3292 /*
3293 if (LayerMaskInt[0]!=0) {
3294 for(int32_t i=c; i<(c&0xF0)+16; i++) {
3295 put_flags(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3296 }
3297 }
3298 */
3299 }
3300
3301 if(ShowMisalignments)
3302 {
3303 if(c<16)
3304 {
3305 check_alignments(dest,x,y,scr);
3306 }
3307 else if(c>159)
3308 {
3309 check_alignments(dest,x,y-160,scr);
3310 }
3311 }
3312
3313 resize_mouse_pos=false;
3314
3315 }
3316
3317 void zmap::drawcolumn(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3318 {
3319 if(map<0)
3320 map=currmap;
3321
3322 if(scr<0)
3323 scr=currscr;
3324
3325 mapscr* layer=AbsoluteScr(map,scr);
3326 int32_t layermap=0, layerscreen=0;
3327
3328 if(!(layer->valid&mVALID))
3329 {
3330 // rectfill(dest,x,y,x+15,y+175,dvc(0+1));
3331 rectfill(dest,x,y,x+15,y+175,vc(1));
3332 return;
3333 }
3334
3335 int32_t dark = layer->flags&4;
3336
3337 resize_mouse_pos=true;
3338
3339
3340 if(LayerMaskInt[0]==0)
3341 {
3342 rectfill(dest,x,y,x+15,y+175,0);
3343 }
3344
3345 // int32_t cs=2;
3346
3347 for(int32_t k=1; k<3; k++)
3348 {
3349 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3350 {
3351 layermap=layer->layermap[k]-1;
3352
3353 if(layermap>-1 && layermap<map_count)
3354 {
3355 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3356
3357 for(int32_t i=c; i<176; i+=16)
3358 {
3359 auto data = TheMaps[layerscreen].data[i];
3360 auto cs = TheMaps[layerscreen].cset[i];
3361 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3362 }
3363 }
3364 }
3365 }
3366
3367 if(LayerMaskInt[0]!=0)
3368 {
3369 for(int32_t i=c; i<176; i+=16)
3370 {
3371 word cmbdat = layer->data[i];
3372 byte cmbcset = layer->cset[i];
3373 int32_t cmbflag = layer->sflag[i];
3374 drawcombo(dest,x,(i&0xF0)+y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3375 (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3376 }
3377 }
3378
3379 for(int32_t k=0; k<2; k++)
3380 {
3381 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3382 {
3383 layermap=layer->layermap[k]-1;
3384
3385 if(layermap>-1 && layermap<map_count)
3386 {
3387 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3388
3389 for(int32_t i=c; i<176; i+=16)
3390 {
3391 auto data = TheMaps[layerscreen].data[i];
3392 auto cs = TheMaps[layerscreen].cset[i];
3393 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3394 }
3395 }
3396 }
3397 }
3398
3399 int32_t doortype[4];
3400
3401 for(int32_t i=0; i<4; i++)
3402 {
3403 switch(layer->door[i])
3404 {
3405 case dOPEN:
3406 doortype[i]=dt_pass;
3407 break;
3408
3409 case dLOCKED:
3410 doortype[i]=dt_lock;
3411 break;
3412
3413 case d1WAYSHUTTER:
3414 case dSHUTTER:
3415 doortype[i]=dt_shut;
3416 break;
3417
3418 case dBOSS:
3419 doortype[i]=dt_boss;
3420 break;
3421
3422 case dBOMB:
3423 doortype[i]=dt_bomb;
3424 break;
3425 }
3426 }
3427
3428 if((c&0x0F)==0)
3429 {
3430 switch(layer->door[left])
3431 {
3432
3433 case dBOMB:
3434 case dOPEN:
3435 case dLOCKED:
3436 case d1WAYSHUTTER:
3437 case dSHUTTER:
3438 case dBOSS:
3439 // put_door(dest,64,left,doortype[left],x+256,y,true);
3440 put_door(dest,64,left,doortype[left],x,y,true,scr);
3441 break;
3442 }
3443 }
3444 else if((c&0x0F)==15)
3445 {
3446 switch(layer->door[right])
3447 {
3448 case dBOMB:
3449 case dOPEN:
3450 case dLOCKED:
3451 case d1WAYSHUTTER:
3452 case dSHUTTER:
3453 case dBOSS:
3454 put_door(dest,78,right,doortype[right],x-16,y,true,scr);
3455 break;
3456 }
3457 }
3458
3459 for(int32_t k=2; k<4; k++)
3460 {
3461 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3462 {
3463 layermap=layer->layermap[k]-1;
3464
3465 if(layermap>-1 && layermap<map_count)
3466 {
3467 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3468
3469 for(int32_t i=c; i<176; i+=16)
3470 {
3471 auto data = TheMaps[layerscreen].data[i];
3472 auto cs = TheMaps[layerscreen].cset[i];
3473 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3474 }
3475 }
3476 }
3477 }
3478
3479 //Overhead L0
3480 if(LayerMaskInt[0]!=0)
3481 {
3482 for(int32_t i=c; i<176; i+=16)
3483 {
3484 auto data = TheMaps[layerscreen].data[i];
3485 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3486 auto cs = TheMaps[layerscreen].cset[i];
3487 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0);
3488 }
3489 }
3490 //Overhead L1/2
3491 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3492 {
3493 for(int32_t k = 0; k < 2; ++k)
3494 {
3495 if(LayerMaskInt[k+1]!=0)
3496 {
3497 layermap=layer->layermap[k]-1;
3498
3499 if(layermap>-1 && layermap<map_count)
3500 {
3501 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3502 for(int32_t i=c; i<176; i+=16)
3503 {
3504 auto data = TheMaps[layerscreen].data[i];
3505 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3506 auto cs = TheMaps[layerscreen].cset[i];
3507 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3508 }
3509 }
3510 }
3511 }
3512 }
3513
3514
3515 for(int32_t k=4; k<6; k++)
3516 {
3517 if(LayerMaskInt[k+1]!=0)
3518 {
3519 layermap=layer->layermap[k]-1;
3520
3521 if(layermap>-1 && layermap<map_count)
3522 {
3523 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3524
3525 for(int32_t i=c; i<176; i+=16)
3526 {
3527 auto data = TheMaps[layerscreen].data[i];
3528 auto cs = TheMaps[layerscreen].cset[i];
3529 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3530 }
3531 }
3532 }
3533 }
3534
3535 if(flags&cWALK)
3536 {
3537 if(LayerMaskInt[0]!=0)
3538 {
3539 for(int32_t i=c&0xF; i<176; i+=16)
3540 {
3541 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, -1, map,scr);
3542 }
3543 }
3544
3545 for(int32_t k=0; k<2; k++)
3546 {
3547 if(LayerMaskInt[k+1]!=0)
3548 {
3549 for(int32_t i=c&0xF; i<176; i+=16)
3550 {
3551 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, k, map,scr);
3552 }
3553 }
3554 }
3555 }
3556
3557 if(flags&cFLAGS)
3558 {
3559 if(LayerMaskInt[CurrentLayer]!=0)
3560 {
3561 for(int32_t i=c; i<176; i+=16)
3562 {
3563 if(CurrentLayer==0)
3564 {
3565 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3566 }
3567 else
3568 {
3569 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3570
3571 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3572 {
3573 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,
3574 TheMaps[_lscr].data[i],
3575 TheMaps[_lscr].cset[i], flags|dark,
3576 TheMaps[_lscr].sflag[i]);
3577 }
3578 }
3579 }
3580 }
3581 }
3582
3583 if(ShowMisalignments)
3584 {
3585 if((c&0x0F)==0)
3586 {
3587 check_alignments(dest,x,y,scr);
3588 }
3589 else if((c&0x0F)==15)
3590 {
3591 check_alignments(dest,x-240,y,scr);
3592 }
3593 }
3594
3595 resize_mouse_pos=false;
3596 }
3597
3598 void zmap::drawblock(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3599 {
3600 if(map<0)
3601 map=currmap;
3602
3603 if(scr<0)
3604 scr=currscr;
3605
3606 mapscr* layer=AbsoluteScr(map,scr);
3607 int32_t layermap=0, layerscreen=0;
3608
3609 if(!(layer->valid&mVALID))
3610 {
3611 // rectfill(dest,x,y,x+15,y+15,dvc(0+1));
3612 rectfill(dest,x,y,x+15,y+15,vc(1));
3613 return;
3614 }
3615
3616 int32_t dark = layer->flags&4;
3617
3618 resize_mouse_pos=true;
3619
3620 if(LayerMaskInt[0]!=0)
3621 {
3622 rectfill(dest,x,y,x+15,y+15,0);
3623 }
3624
3625 for(int32_t k=1; k<3; k++)
3626 {
3627 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3628 {
3629 layermap=layer->layermap[k]-1;
3630
3631 if(layermap>-1 && layermap<map_count)
3632 {
3633 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3634
3635 auto data = TheMaps[layerscreen].data[c];
3636 auto cs = TheMaps[layerscreen].cset[c];
3637 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3638 }
3639 }
3640 }
3641
3642 // int32_t cs=2;
3643 if(LayerMaskInt[0]!=0)
3644 {
3645 word cmbdat = layer->data[c];
3646 byte cmbcset = layer->cset[c];
3647 int32_t cmbflag = layer->sflag[c];
3648 drawcombo(dest,x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3649 (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3650 }
3651
3652
3653 for(int32_t k=0; k<2; k++)
3654 {
3655 if(LayerMaskInt[k+1]!=0)
3656 {
3657 layermap=layer->layermap[k]-1;
3658
3659 if(layermap>-1 && layermap<map_count)
3660 {
3661 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3662
3663 auto data = TheMaps[layerscreen].data[c];
3664 auto cs = TheMaps[layerscreen].cset[c];
3665 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3666 }
3667 }
3668 }
3669
3670 for(int32_t k=2; k<4; k++)
3671 {
3672 if(LayerMaskInt[k+1]!=0)
3673 {
3674 layermap=layer->layermap[k]-1;
3675
3676 if(layermap>-1 && layermap<map_count)
3677 {
3678 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3679 auto data = TheMaps[layerscreen].data[c];
3680 auto cs = TheMaps[layerscreen].cset[c];
3681 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3682 }
3683 }
3684 }
3685
3686 //Overhead L0
3687 if(LayerMaskInt[0]!=0)
3688 {
3689 auto data = TheMaps[layerscreen].data[c];
3690 if(combo_class_buf[combobuf[data].type].overhead)
3691 {
3692 auto cs = TheMaps[layerscreen].cset[c];
3693 drawcombo(dest,x,y,data,cs,0,0);
3694 }
3695 }
3696 //Overhead L1/2
3697 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3698 {
3699 for(int32_t k = 0; k < 2; ++k)
3700 {
3701 if(LayerMaskInt[k+1]!=0)
3702 {
3703 layermap=layer->layermap[k]-1;
3704
3705 if(layermap>-1 && layermap<map_count)
3706 {
3707 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3708 auto data = TheMaps[layerscreen].data[c];
3709 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3710 auto cs = TheMaps[layerscreen].cset[c];
3711 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3712 }
3713 }
3714 }
3715 }
3716
3717
3718 for(int32_t k=4; k<6; k++)
3719 {
3720 if(LayerMaskInt[k+1]!=0)
3721 {
3722 layermap=layer->layermap[k]-1;
3723
3724 if(layermap>-1 && layermap<map_count)
3725 {
3726 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3727 auto data = TheMaps[layerscreen].data[c];
3728 auto cs = TheMaps[layerscreen].cset[c];
3729 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3730 }
3731 }
3732 }
3733
3734 if(flags&cWALK)
3735 {
3736 if(LayerMaskInt[0]!=0)
3737 {
3738 put_walkflags_layered_external(dest,x,y,c,-1, map,scr);
3739 }
3740
3741 for(int32_t k=0; k<2; k++)
3742 {
3743 if(LayerMaskInt[k+1]!=0)
3744 {
3745 put_walkflags_layered_external(dest,x,y,c,k, map,scr);
3746 }
3747 }
3748 }
3749
3750 if(flags&cFLAGS)
3751 {
3752 if(LayerMaskInt[CurrentLayer]!=0)
3753 {
3754 int32_t i = c;
3755 //for(int32_t i=c; i==c; i++)
3756 {
3757 if(CurrentLayer==0)
3758 {
3759 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3760 }
3761 else
3762 {
3763 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3764
3765 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3766 {
3767 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,
3768 TheMaps[_lscr].data[i],
3769 TheMaps[_lscr].cset[i], flags|dark,
3770 TheMaps[_lscr].sflag[i]);
3771 }
3772 }
3773 }
3774 }
3775 }
3776
3777 if(ShowMisalignments)
3778 {
3779 switch(c)
3780 {
3781 case 0:
3782 check_alignments(dest,x,y,scr);
3783 break;
3784
3785 case 15:
3786 check_alignments(dest,x-240,y,scr);
3787 break;
3788
3789 case 160:
3790 check_alignments(dest,x,y-160,scr);
3791 break;
3792
3793 case 175:
3794 check_alignments(dest,x-240,y-160,scr);
3795 break;
3796 }
3797 }
3798
3799 resize_mouse_pos=false;
3800
3801 }
3802
3803 void zmap::drawstaticblock(BITMAP* dest,int32_t x,int32_t y)
3804 {
3805 if (InvalidBG == 2)
3806 {
3807 draw_checkerboard(dest, x, y, 16);
3808 }
3809 else if(InvalidBG == 1)
3810 {
3811 for(int32_t dy=0; dy<16; dy++)
3812 {
3813 for(int32_t dx=0; dx<16; dx++)
3814 {
3815 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3816 }
3817 }
3818 }
3819 else
3820 {
3821 rectfill(dest, x, y, x+15, y+15, vc(0));
3822 rect(dest, x, y, x+15, y+15, vc(15));
3823 line(dest, x, y, x+15, y+15, vc(15));
3824 line(dest, x, y+15, x+15, y, vc(15));
3825 }
3826 }
3827
3828 void zmap::drawstaticcolumn(BITMAP* dest,int32_t x,int32_t y)
3829 {
3830 if (InvalidBG == 2)
3831 {
3832 for(int32_t q = 0; q < 11; ++q)
3833 draw_checkerboard(dest, x, y + q * 16, 16);
3834 }
3835 else if(InvalidBG == 1)
3836 {
3837 for(int32_t dy=0; dy<176; dy++)
3838 {
3839 for(int32_t dx=0; dx<16; dx++)
3840 {
3841 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3842 }
3843 }
3844 }
3845 else
3846 {
3847 rectfill(dest, x, y, x+15, y+175, vc(0));
3848 rect(dest, x, y, x+15, y+175, vc(15));
3849 line(dest, x, y, x+15, y+175, vc(15));
3850 line(dest, x, y+175, x+15, y, vc(15));
3851 }
3852 }
3853
3854 void zmap::drawstaticrow(BITMAP* dest,int32_t x,int32_t y)
3855 {
3856 if (InvalidBG == 2)
3857 {
3858 for (int32_t q = 0; q < 16; ++q)
3859 draw_checkerboard(dest, x + q * 16, y, 16);
3860 }
3861 else if(InvalidBG == 1)
3862 {
3863 for(int32_t dy=0; dy<16; dy++)
3864 {
3865 for(int32_t dx=0; dx<256; dx++)
3866 {
3867 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3868 }
3869 }
3870 }
3871 else
3872 {
3873 rectfill(dest, x, y, x+255, y+15, vc(0));
3874 rect(dest, x, y, x+255, y+15, vc(15));
3875 line(dest, x, y, x+255, y+15, vc(15));
3876 line(dest, x, y+15, x+255, y, vc(15));
3877 }
3878 }
3879
3880 void zmap::draw_template(BITMAP* dest,int32_t x,int32_t y)
3881 {
3882 for(int32_t i=0; i<176; i++)
3883 {
3884 word cmbdat = screens[TEMPLATE].data[i];
3885 byte cmbcset = screens[TEMPLATE].cset[i];
3886 int32_t cmbflag = screens[TEMPLATE].sflag[i];
3887 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3888 }
3889 }
3890
3891 void zmap::draw_template2(BITMAP* dest,int32_t x,int32_t y)
3892 {
3893 for(int32_t i=0; i<176; i++)
3894 {
3895 word cmbdat = screens[TEMPLATE2].data[i];
3896 byte cmbcset = screens[TEMPLATE2].cset[i];
3897 int32_t cmbflag = screens[TEMPLATE2].sflag[i];
3898 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3899 }
3900 }
3901
3902 void zmap::draw_secret(BITMAP *dest, int32_t pos)
3903 {
3904 word cmbdat = screens[TEMPLATE].data[pos];
3905 byte cmbcset = screens[TEMPLATE].cset[pos];
3906 int32_t cmbflag = screens[TEMPLATE].sflag[pos];
3907 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3908 }
3909
3910 void zmap::draw_secret2(BITMAP *dest, int32_t scombo)
3911 {
3912 word cmbdat = screens[currscr].secretcombo[scombo];
3913 byte cmbcset = screens[currscr].secretcset[scombo];
3914 byte cmbflag = screens[currscr].secretflag[scombo];
3915 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3916 }
3917
3918 void zmap::scroll(int32_t dir, bool warp)
3919 {
3920 if(currmap<map_count)
3921 {
3922 switch(dir)
3923 {
3924 case up:
3925 if(warp && Map.CurrScr()->flags2&wfUP)
3926 {
3927 dowarp(1,Map.CurrScr()->sidewarpindex&3);
3928 }
3929 else if(currscr>15)
3930 {
3931 setCurrScr(currscr-16);
3932 }
3933
3934 break;
3935
3936 case down:
3937 if(warp && Map.CurrScr()->flags2&wfDOWN)
3938 {
3939 dowarp(1,(Map.CurrScr()->sidewarpindex>>2)&3);
3940 }
3941 else if(currscr<MAPSCRS-16)
3942 {
3943 setCurrScr(currscr+16);
3944 }
3945
3946 break;
3947
3948 case left:
3949 if(warp && Map.CurrScr()->flags2&wfLEFT)
3950 {
3951 dowarp(1,(Map.CurrScr()->sidewarpindex>>4)&3);
3952 }
3953 else if(currscr&15)
3954 {
3955 setCurrScr(currscr-1);
3956 }
3957
3958 break;
3959
3960 case right:
3961 if(warp && Map.CurrScr()->flags2&wfRIGHT)
3962 {
3963 dowarp(1,(Map.CurrScr()->sidewarpindex>>6)&3);
3964 }
3965 else if((currscr&15)<15 && currscr<MAPSCRS-1)
3966 {
3967 setCurrScr(currscr+1);
3968 }
3969
3970 break;
3971 }
3972 }
3973 }
3974
3975 void fetch_door(int side, int door, int dcs, word data[176], byte cset[176])
3976 {
3977 switch(side)
3978 {
3979 case up:
3980 switch(door)
3981 {
3982 case dWALL:
3983 case dBOMB:
3984 case dWALK:
3985 data[7] = DoorComboSets[dcs].doorcombo_u[dt_wall][0];
3986 cset[7] = DoorComboSets[dcs].doorcset_u[dt_wall][0];
3987 data[8] = DoorComboSets[dcs].doorcombo_u[dt_wall][1];
3988 cset[8] = DoorComboSets[dcs].doorcset_u[dt_wall][1];
3989 data[23] = DoorComboSets[dcs].doorcombo_u[dt_wall][2];
3990 cset[23] = DoorComboSets[dcs].doorcset_u[dt_wall][2];
3991 data[24] = DoorComboSets[dcs].doorcombo_u[dt_wall][3];
3992 cset[24] = DoorComboSets[dcs].doorcset_u[dt_wall][3];
3993 break;
3994
3995 default:
3996 data[7] = DoorComboSets[dcs].doorcombo_u[dt_pass][0];
3997 cset[7] = DoorComboSets[dcs].doorcset_u[dt_pass][0];
3998 data[8] = DoorComboSets[dcs].doorcombo_u[dt_pass][1];
3999 cset[8] = DoorComboSets[dcs].doorcset_u[dt_pass][1];
4000 data[23] = DoorComboSets[dcs].doorcombo_u[dt_pass][2];
4001 cset[23] = DoorComboSets[dcs].doorcset_u[dt_pass][2];
4002 data[24] = DoorComboSets[dcs].doorcombo_u[dt_pass][3];
4003 cset[24] = DoorComboSets[dcs].doorcset_u[dt_pass][3];
4004 break;
4005 }
4006
4007 break;
4008
4009 case down:
4010 switch(door)
4011 {
4012 case dWALL:
4013 case dBOMB:
4014 case dWALK:
4015 data[151] = DoorComboSets[dcs].doorcombo_d[dt_wall][0];
4016 cset[151] = DoorComboSets[dcs].doorcset_d[dt_wall][0];
4017 data[152] = DoorComboSets[dcs].doorcombo_d[dt_wall][1];
4018 cset[152] = DoorComboSets[dcs].doorcset_d[dt_wall][1];
4019 data[167] = DoorComboSets[dcs].doorcombo_d[dt_wall][2];
4020 cset[167] = DoorComboSets[dcs].doorcset_d[dt_wall][2];
4021 data[168] = DoorComboSets[dcs].doorcombo_d[dt_wall][3];
4022 cset[168] = DoorComboSets[dcs].doorcset_d[dt_wall][3];
4023 break;
4024
4025 default:
4026 data[151] = DoorComboSets[dcs].doorcombo_d[dt_pass][0];
4027 cset[151] = DoorComboSets[dcs].doorcset_d[dt_pass][0];
4028 data[152] = DoorComboSets[dcs].doorcombo_d[dt_pass][1];
4029 cset[152] = DoorComboSets[dcs].doorcset_d[dt_pass][1];
4030 data[167] = DoorComboSets[dcs].doorcombo_d[dt_pass][2];
4031 cset[167] = DoorComboSets[dcs].doorcset_d[dt_pass][2];
4032 data[168] = DoorComboSets[dcs].doorcombo_d[dt_pass][3];
4033 cset[168] = DoorComboSets[dcs].doorcset_d[dt_pass][3];
4034 break;
4035 }
4036
4037 break;
4038
4039 case left:
4040 switch(door)
4041 {
4042 case dWALL:
4043 case dBOMB:
4044 case dWALK:
4045 data[64] = DoorComboSets[dcs].doorcombo_l[dt_wall][0];
4046 cset[64] = DoorComboSets[dcs].doorcset_l[dt_wall][0];
4047 data[65] = DoorComboSets[dcs].doorcombo_l[dt_wall][1];
4048 cset[65] = DoorComboSets[dcs].doorcset_l[dt_wall][1];
4049 data[80] = DoorComboSets[dcs].doorcombo_l[dt_wall][2];
4050 cset[80] = DoorComboSets[dcs].doorcset_l[dt_wall][2];
4051 data[81] = DoorComboSets[dcs].doorcombo_l[dt_wall][3];
4052 cset[81] = DoorComboSets[dcs].doorcset_l[dt_wall][3];
4053 data[96] = DoorComboSets[dcs].doorcombo_l[dt_wall][4];
4054 cset[96] = DoorComboSets[dcs].doorcset_l[dt_wall][4];
4055 data[97] = DoorComboSets[dcs].doorcombo_l[dt_wall][5];
4056 cset[97] = DoorComboSets[dcs].doorcset_l[dt_wall][5];
4057 break;
4058
4059 default:
4060 data[64] = DoorComboSets[dcs].doorcombo_l[dt_pass][0];
4061 cset[64] = DoorComboSets[dcs].doorcset_l[dt_pass][0];
4062 data[65] = DoorComboSets[dcs].doorcombo_l[dt_pass][1];
4063 cset[65] = DoorComboSets[dcs].doorcset_l[dt_pass][1];
4064 data[80] = DoorComboSets[dcs].doorcombo_l[dt_pass][2];
4065 cset[80] = DoorComboSets[dcs].doorcset_l[dt_pass][2];
4066 data[81] = DoorComboSets[dcs].doorcombo_l[dt_pass][3];
4067 cset[81] = DoorComboSets[dcs].doorcset_l[dt_pass][3];
4068 data[96] = DoorComboSets[dcs].doorcombo_l[dt_pass][4];
4069 cset[96] = DoorComboSets[dcs].doorcset_l[dt_pass][4];
4070 data[97] = DoorComboSets[dcs].doorcombo_l[dt_pass][5];
4071 cset[97] = DoorComboSets[dcs].doorcset_l[dt_pass][5];
4072 break;
4073 }
4074
4075 break;
4076
4077 case right:
4078 switch(door)
4079 {
4080 case dWALL:
4081 case dBOMB:
4082 case dWALK:
4083 data[78] = DoorComboSets[dcs].doorcombo_r[dt_wall][0];
4084 cset[78] = DoorComboSets[dcs].doorcset_r[dt_wall][0];
4085 data[79] = DoorComboSets[dcs].doorcombo_r[dt_wall][1];
4086 cset[79] = DoorComboSets[dcs].doorcset_r[dt_wall][1];
4087 data[94] = DoorComboSets[dcs].doorcombo_r[dt_wall][2];
4088 cset[94] = DoorComboSets[dcs].doorcset_r[dt_wall][2];
4089 data[95] = DoorComboSets[dcs].doorcombo_r[dt_wall][3];
4090 cset[95] = DoorComboSets[dcs].doorcset_r[dt_wall][3];
4091 data[110] = DoorComboSets[dcs].doorcombo_r[dt_wall][4];
4092 cset[110] = DoorComboSets[dcs].doorcset_r[dt_wall][4];
4093 data[111] = DoorComboSets[dcs].doorcombo_r[dt_wall][5];
4094 cset[111] = DoorComboSets[dcs].doorcset_r[dt_wall][5];
4095 break;
4096
4097 default:
4098 data[78] = DoorComboSets[dcs].doorcombo_r[dt_pass][0];
4099 cset[78] = DoorComboSets[dcs].doorcset_r[dt_pass][0];
4100 data[79] = DoorComboSets[dcs].doorcombo_r[dt_pass][1];
4101 cset[79] = DoorComboSets[dcs].doorcset_r[dt_pass][1];
4102 data[94] = DoorComboSets[dcs].doorcombo_r[dt_pass][2];
4103 cset[94] = DoorComboSets[dcs].doorcset_r[dt_pass][2];
4104 data[95] = DoorComboSets[dcs].doorcombo_r[dt_pass][3];
4105 cset[95] = DoorComboSets[dcs].doorcset_r[dt_pass][3];
4106 data[110] = DoorComboSets[dcs].doorcombo_r[dt_pass][4];
4107 cset[110] = DoorComboSets[dcs].doorcset_r[dt_pass][4];
4108 data[111] = DoorComboSets[dcs].doorcombo_r[dt_pass][5];
4109 cset[111] = DoorComboSets[dcs].doorcset_r[dt_pass][5];
4110 break;
4111 }
4112
4113 break;
4114 }
4115 }
4116 void zmap::DoPutDoorCommand(int side, int door, bool force)
4117 {
4118 if(!force && screens[currscr].door[side] == door)
4119 return;
4120 bool already_list = InListCommand();
4121 if(!already_list)
4122 StartListCommand();
4123 DoSetDoorCommand(currscr,side,door);
4124 if(door != dNONE)
4125 {
4126 word data[176] = {0};
4127 byte cset[176] = {0};
4128 fetch_door(side, door, screens[currscr].door_combo_set, data, cset);
4129 for(int q = 0; q < 176; ++q)
4130 if(data[q])
4131 DoSetComboCommand(currmap,currscr,q,data[q],cset[q]);
4132 }
4133 if(!already_list)
4134 FinishListCommand();
4135 }
4136 void zmap::putdoor(int32_t scr,int32_t side,int32_t door)
4137 {
4138 if(screens[scr].door[side] == door)
4139 return;
4140 screens[scr].door[side] = door;
4141 if(door != dNONE)
4142 {
4143 word data[176] = {0};
4144 byte cset[176] = {0};
4145 fetch_door(side, door, screens[scr].door_combo_set, data, cset);
4146 for(int q = 0; q < 176; ++q)
4147 if(data[q])
4148 {
4149 screens[scr].data[q] = data[q];
4150 screens[scr].cset[q] = cset[q];
4151 }
4152 }
4153 }
4154
4155 void list_command::execute()
4156 {
4157 for (auto command : commands)
4158 {
4159 command->execute();
4160 }
4161 }
4162
4163 void list_command::undo()
4164 {
4165 for (int i = commands.size() - 1; i >= 0; i--)
4166 {
4167 commands[i]->undo();
4168 }
4169 }
4170
4171 int list_command::size()
4172 {
4173 int s = 0;
4174 for (auto command : commands)
4175 {
4176 s += command->size();
4177 }
4178 return s;
4179 }
4180
4181 void set_combo_command::execute()
4182 {
4183 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4184 if(!mapscr_ptr) return;
4185 if (combo != -1) mapscr_ptr->data[pos] = combo;
4186 mapscr_ptr->cset[pos] = cset;
4187 }
4188
4189 void set_combo_command::undo()
4190 {
4191 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4192 if(!mapscr_ptr) return;
4193 if (combo != -1) mapscr_ptr->data[pos] = prev_combo;
4194 mapscr_ptr->cset[pos] = prev_cset;
4195 }
4196
4197 set_ffc_command::data_t set_ffc_command::create_data(const ffcdata& ffc)
4198 {
4199 std::array<int, 2> inita_arr;
4200 std::copy(std::begin(ffc.inita), std::end(ffc.inita), inita_arr.begin());
4201 std::array<int, 8> initd_arr;
4202 std::copy(std::begin(ffc.initd), std::end(ffc.initd), initd_arr.begin());
4203
4204 return {
4205 .x = ffc.x,
4206 .y = ffc.y,
4207 .vx = ffc.vx,
4208 .vy = ffc.vy,
4209 .ax = ffc.ax,
4210 .ay = ffc.ay,
4211 .data = ffc.data,
4212 .cset = ffc.cset,
4213 .delay = ffc.delay,
4214 .link = ffc.link,
4215 .script = ffc.script,
4216 .tw = ffc.txsz,
4217 .th = ffc.tysz,
4218 .ew = ffc.hit_width,
4219 .eh = ffc.hit_height,
4220 .flags = ffc.flags,
4221 .inita = inita_arr,
4222 .initd = initd_arr,
4223 };
4224 }
4225
4226 void set_ffc_command::execute()
4227 {
4228 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4229 if(!mapscr_ptr) return;
4230
4231 mapscr_ptr->ffcs[i].x = data.x;
4232 mapscr_ptr->ffcs[i].y = data.y;
4233 mapscr_ptr->ffcs[i].vx = data.vx;
4234 mapscr_ptr->ffcs[i].vy = data.vy;
4235 mapscr_ptr->ffcs[i].ax = data.ax;
4236 mapscr_ptr->ffcs[i].ay = data.ay;
4237 mapscr_ptr->ffcs[i].data = data.data;
4238 mapscr_ptr->ffcs[i].cset = data.cset;
4239 mapscr_ptr->ffcs[i].delay = data.delay;
4240 mapscr_ptr->ffcs[i].link = data.link;
4241 mapscr_ptr->ffcs[i].script = data.script;
4242 mapscr_ptr->ffcs[i].flags = data.flags;
4243 mapscr_ptr->ffEffectWidth(i, data.ew);
4244 mapscr_ptr->ffEffectHeight(i, data.eh);
4245 mapscr_ptr->ffTileWidth(i, data.tw);
4246 mapscr_ptr->ffTileHeight(i, data.th);
4247 std::copy(std::begin(data.inita), std::end(data.inita), std::begin(mapscr_ptr->ffcs[i].inita));
4248 std::copy(std::begin(data.initd), std::end(data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4249 mapscr_ptr->ffcCountMarkDirty();
4250 mapscr_ptr->ffcs[i].updateSolid();
4251 }
4252
4253 void set_ffc_command::undo()
4254 {
4255 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4256 if(!mapscr_ptr) return;
4257
4258 mapscr_ptr->ffcs[i].x = prev_data.x;
4259 mapscr_ptr->ffcs[i].y = prev_data.y;
4260 mapscr_ptr->ffcs[i].vx = prev_data.vx;
4261 mapscr_ptr->ffcs[i].vy = prev_data.vy;
4262 mapscr_ptr->ffcs[i].ax = prev_data.ax;
4263 mapscr_ptr->ffcs[i].ay = prev_data.ay;
4264 mapscr_ptr->ffcs[i].data = prev_data.data;
4265 mapscr_ptr->ffcs[i].cset = prev_data.cset;
4266 mapscr_ptr->ffcs[i].delay = prev_data.delay;
4267 mapscr_ptr->ffcs[i].link = prev_data.link;
4268 mapscr_ptr->ffcs[i].script = prev_data.script;
4269 mapscr_ptr->ffcs[i].flags = prev_data.flags;
4270 mapscr_ptr->ffEffectWidth(i, prev_data.ew);
4271 mapscr_ptr->ffEffectHeight(i, prev_data.eh);
4272 mapscr_ptr->ffTileWidth(i, prev_data.tw);
4273 mapscr_ptr->ffTileHeight(i, prev_data.th);
4274 std::copy(std::begin(prev_data.inita), std::end(prev_data.inita), std::begin(mapscr_ptr->ffcs[i].inita));
4275 std::copy(std::begin(prev_data.initd), std::end(prev_data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4276 mapscr_ptr->ffcCountMarkDirty();
4277 mapscr_ptr->ffcs[i].updateSolid();
4278 }
4279
4280 void set_flag_command::execute()
4281 {
4282 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4283 if(!mapscr_ptr) return;
4284 mapscr_ptr->sflag[pos] = flag;
4285 }
4286
4287 void set_flag_command::undo()
4288 {
4289 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4290 if(!mapscr_ptr) return;
4291 mapscr_ptr->sflag[pos] = prev_flag;
4292 }
4293
4294 void set_door_command::execute()
4295 {
4296 Map.AbsoluteScr(view_map, view_scr)->door[side] = door;
4297 }
4298
4299 void set_door_command::undo()
4300 {
4301 Map.AbsoluteScr(view_map, view_scr)->door[side] = prev_door;
4302 }
4303
4304 void set_dcs_command::execute()
4305 {
4306 Map.AbsoluteScr(view_map, view_scr)->door_combo_set = dcs;
4307 }
4308
4309 void set_dcs_command::undo()
4310 {
4311 Map.AbsoluteScr(view_map, view_scr)->door_combo_set = prev_dcs;
4312 }
4313
4314 void paste_screen_command::execute()
4315 {
4316 perform(screen.get());
4317 }
4318
4319 void paste_screen_command::undo()
4320 {
4321 if (prev_screens.size() > 1)
4322 {
4323 ASSERT(type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen);
4324 ASSERT(prev_screens.size() == 128);
4325 for (int i = 0; i < 128; i++)
4326 {
4327 copy_mapscr(Map.AbsoluteScr(view_map, i), prev_screens[i].get());
4328 // TODO: why not just this?
4329 // If this changes, also change the line in PasteAllToAll and PasteAll to use simply copy assignment.
4330 // *Map.AbsoluteScr(map, i) = *prev_screens[i].get();
4331 }
4332 return;
4333 }
4334
4335 perform(prev_screens[0].get());
4336 }
4337
4338 int paste_screen_command::size()
4339 {
4340 return prev_screens.size() + 1;
4341 }
4342
4343 void paste_screen_command::perform(mapscr* to)
4344 {
4345 if (to)
4346 {
4347 switch (type) {
4348 case ScreenAll: Map.PasteAll(*to); break;
4349 case ScreenAllToEveryScreen: Map.PasteAllToAll(*to); break;
4350 case ScreenData: Map.PasteScreenData(*to); break;
4351 case ScreenDoors: Map.PasteDoors(*to); break;
4352 case ScreenEnemies: Map.PasteEnemies(*to); break;
4353 case ScreenFFCombos: Map.PasteFFCombos(*to); break;
4354 case ScreenGuy: Map.PasteGuy(*to); break;
4355 case ScreenLayers: Map.PasteLayers(*to); break;
4356 case ScreenPalette: Map.PastePalette(*to); break;
4357 case ScreenPartial: Map.Paste(*to); break;
4358 case ScreenPartialToEveryScreen: Map.PasteToAll(*to); break;
4359 case ScreenRoom: Map.PasteRoom(*to); break;
4360 case ScreenSecretCombos: Map.PasteSecretCombos(*to); break;
4361 case ScreenUnderCombo: Map.PasteUnderCombo(*to); break;
4362 case ScreenWarpLocations: Map.PasteWarpLocations(*to); break;
4363 case ScreenWarps: Map.PasteWarps(*to); break;
4364 }
4365 }
4366 else
4367 {
4368 Map.clearscr(view_scr);
4369 }
4370 refresh(rALL);
4371 }
4372
4373 void set_screen_command::execute()
4374 {
4375 if (screen)
4376 {
4377 copy_mapscr(Map.AbsoluteScr(view_map, view_scr), screen.get());
4378 }
4379 else
4380 {
4381 Map.clearscr(view_scr);
4382 }
4383 refresh(rALL);
4384 }
4385
4386 void set_screen_command::undo()
4387 {
4388 if (prev_screen)
4389 {
4390 copy_mapscr(Map.AbsoluteScr(view_map, view_scr), prev_screen.get());
4391 }
4392 else
4393 {
4394 Map.clearscr(view_scr);
4395 }
4396 refresh(rALL);
4397 }
4398
4399 int set_screen_command::size()
4400 {
4401 return (prev_screen ? 1 : 0) + (screen ? 1 : 0);
4402 }
4403
4404 extern byte relational_tile_grid[11+(rtgyo*2)][16+(rtgxo*2)];
4405
4406 void tile_grid_draw_command::execute()
4407 {
4408 util::copy_2d_array<byte, 15, 20>(tile_grid, relational_tile_grid);
4409 }
4410
4411 void tile_grid_draw_command::undo()
4412 {
4413 util::copy_2d_array<byte, 15, 20>(prev_tile_grid, relational_tile_grid);
4414 }
4415
4416 static std::shared_ptr<list_command> current_list_command;
4417 void zmap::StartListCommand()
4418 {
4419 ASSERT(!current_list_command);
4420 current_list_command.reset(new list_command);
4421 }
4422
4423 void zmap::FinishListCommand()
4424 {
4425 if (current_list_command->commands.size() == 1)
4426 {
4427 undo_stack.push_back(current_list_command->commands[0]);
4428 }
4429 else if (current_list_command->commands.size() > 1)
4430 {
4431 undo_stack.push_back(current_list_command);
4432 }
4433 CapCommandHistory();
4434 current_list_command = nullptr;
4435 }
4436
4437 void zmap::RevokeListCommand()
4438 {
4439 current_list_command->undo();
4440 current_list_command = nullptr;
4441 }
4442
4443 bool zmap::InListCommand() const
4444 {
4445 return current_list_command ? true : false;
4446 }
4447
4448 void zmap::ExecuteCommand(std::shared_ptr<user_input_command> command, bool skip_execute)
4449 {
4450 redo_stack = std::stack<std::shared_ptr<user_input_command>>();
4451 if (!skip_execute) command->execute();
4452 if (current_list_command)
4453 {
4454 current_list_command->commands.push_back(command);
4455 if (current_list_command->commands.size() == 1)
4456 {
4457 current_list_command->view_map = command->view_map;
4458 current_list_command->view_scr = command->view_scr;
4459 }
4460 }
4461 else
4462 {
4463 undo_stack.push_back(command);
4464 CapCommandHistory();
4465 }
4466 saved = false;
4467 }
4468
4469 void zmap::UndoCommand()
4470 {
4471 if (undo_stack.size() <= 0) return;
4472
4473 // If not currently looking at the associated screen, first change the view
4474 // and wait for the next call to actually undo this command.
4475 auto command = undo_stack.back();
4476 if (command->view_map != Map.getCurrMap() || command->view_scr != Map.getCurrScr())
4477 {
4478 setCurrentView(command->view_map, command->view_scr);
4479 return;
4480 }
4481
4482 command->undo();
4483 redo_stack.push(command);
4484 undo_stack.pop_back();
4485 saved = false;
4486 }
4487
4488 void zmap::RedoCommand()
4489 {
4490 if (redo_stack.size() <= 0) return;
4491
4492 // If not currently looking at the associated screen, first change the view
4493 // and wait for the next call to actually execute this command.
4494 auto command = redo_stack.top();
4495 if (command->view_map != Map.getCurrMap() || command->view_scr != Map.getCurrScr())
4496 {
4497 setCurrentView(command->view_map, command->view_scr);
4498 return;
4499 }
4500
4501 command->execute();
4502 undo_stack.push_back(command);
4503 redo_stack.pop();
4504 saved = false;
4505 }
4506
4507 9 void zmap::ClearCommandHistory()
4508 {
4509 9 current_list_command = nullptr;
4510 9 undo_stack = std::deque<std::shared_ptr<user_input_command>>();
4511 9 redo_stack = std::stack<std::shared_ptr<user_input_command>>();
4512 9 }
4513
4514 // Extra amount is from mapscr's vectors.
4515 static int size_of_mapscr = sizeof(mapscr) + 4*176;
4516 // Allow the undo system to use roughly 100 MB of memory.
4517 // This doesn't count the memory used by commands that don't store a mapscr,
4518 // but that should be negligible.
4519 9 static int max_command_size = 100e6 / size_of_mapscr;
4520 void zmap::CapCommandHistory()
4521 {
4522 int size;
4523 do
4524 {
4525 size = 0;
4526 for (auto command : undo_stack)
4527 {
4528 size += command->size();
4529 }
4530 if (size > max_command_size) undo_stack.pop_front();
4531 } while (size > max_command_size);
4532 }
4533
4534 void zmap::DoSetComboCommand(int map, int scr, int pos, int combo, int cset)
4535 {
4536 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4537 if(!mapscr_ptr) return;
4538 std::shared_ptr<set_combo_command> command(new set_combo_command);
4539 command->view_map = currmap;
4540 command->view_scr = currscr;
4541 command->map = map;
4542 command->scr = scr;
4543 command->pos = pos;
4544 command->combo = combo;
4545 command->cset = cset;
4546 command->prev_combo = mapscr_ptr->data[pos];
4547 command->prev_cset = mapscr_ptr->cset[pos];
4548 if ((command->combo != -1 && command->prev_combo == command->combo) && command->cset == command->prev_cset)
4549 {
4550 // nothing to do...
4551 return;
4552 }
4553
4554 ExecuteCommand(command);
4555 }
4556
4557 void zmap::DoSetFFCCommand(int map, int scr, int i, set_ffc_command::data_t data)
4558 {
4559 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4560 if(!mapscr_ptr) return;
4561
4562 std::shared_ptr<set_ffc_command> command(new set_ffc_command);
4563
4564 std::array<int, 2> inita_arr;
4565 std::copy(std::begin(mapscr_ptr->ffcs[i].inita), std::end(mapscr_ptr->ffcs[i].inita), inita_arr.begin());
4566 std::array<int, 8> initd_arr;
4567 std::copy(std::begin(mapscr_ptr->ffcs[i].initd), std::end(mapscr_ptr->ffcs[i].initd), initd_arr.begin());
4568
4569 auto prev_data = set_ffc_command::create_data(mapscr_ptr->ffcs[i]);
4570
4571 command->view_map = currmap;
4572 command->view_scr = currscr;
4573 command->map = map;
4574 command->scr = scr;
4575 command->i = i;
4576 command->data = data;
4577 command->prev_data = prev_data;
4578 if (data == prev_data)
4579 {
4580 // nothing to do...
4581 return;
4582 }
4583
4584 ExecuteCommand(command);
4585 }
4586
4587 void zmap::DoSetFlagCommand(int map, int scr, int pos, int flag)
4588 {
4589 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4590 if(!mapscr_ptr) return;
4591 std::shared_ptr<set_flag_command> command(new set_flag_command);
4592 command->view_map = currmap;
4593 command->view_scr = currscr;
4594 command->map = map;
4595 command->scr = scr;
4596 command->pos = pos;
4597 command->flag = flag;
4598 command->prev_flag = mapscr_ptr->sflag[pos];
4599 if (command->flag == command->prev_flag)
4600 {
4601 // nothing to do...
4602 return;
4603 }
4604
4605 ExecuteCommand(command);
4606 }
4607
4608 void zmap::DoSetDoorCommand(int scr, int side, int door)
4609 {
4610 if(screens[scr].door[side] == door)
4611 return;
4612 std::shared_ptr<set_door_command> command(new set_door_command);
4613 command->view_map = currmap;
4614 command->view_scr = scr;
4615 command->side = side;
4616 command->door = door;
4617 command->prev_door = screens[scr].door[side];
4618
4619 ExecuteCommand(command);
4620 }
4621 void zmap::DoSetDCSCommand(int dcs)
4622 {
4623 if(screens[currscr].door_combo_set == dcs)
4624 return;
4625 std::shared_ptr<set_dcs_command> command(new set_dcs_command);
4626 command->view_map = currmap;
4627 command->view_scr = currscr;
4628 command->dcs = dcs;
4629 command->prev_dcs = screens[currscr].door_combo_set;
4630
4631 ExecuteCommand(command);
4632 }
4633
4634 void zmap::DoPasteScreenCommand(PasteCommandType type, int data)
4635 {
4636 std::shared_ptr<paste_screen_command> command(new paste_screen_command);
4637 command->view_map = currmap;
4638 command->view_scr = currscr;
4639 command->type = type;
4640 command->data = data;
4641 command->screen = std::shared_ptr<mapscr>(new mapscr(copymapscr));
4642
4643 if (type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen)
4644 {
4645 for (int i=0; i < 128; i++)
4646 {
4647 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[i])));
4648 }
4649 }
4650 else
4651 {
4652 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[currscr])));
4653 }
4654
4655 ExecuteCommand(command);
4656 }
4657
4658 void zmap::DoClearScreenCommand()
4659 {
4660 std::shared_ptr<set_screen_command> command(new set_screen_command);
4661 command->view_map = currmap;
4662 command->view_scr = currscr;
4663 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(screens[currscr]));
4664 command->screen = std::shared_ptr<mapscr>(nullptr);
4665
4666 ExecuteCommand(command);
4667 }
4668
4669 void zmap::DoTemplateCommand(int floorcombo, int floorcset, int scr)
4670 {
4671 std::shared_ptr<set_screen_command> command(new set_screen_command);
4672 command->view_map = currmap;
4673 command->view_scr = currscr;
4674 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(*Map.CurrScr()));
4675 Template(floorcombo, floorcset, scr);
4676 command->screen = std::shared_ptr<mapscr>(new mapscr(*Map.CurrScr()));
4677
4678 ExecuteCommand(command, true);
4679 }
4680
4681 void zmap::Copy()
4682 {
4683 if(screens[currscr].valid&mVALID)
4684 {
4685 copy_mapscr(&copymapscr, &screens[currscr]);
4686 //copymapscr=screens[currscr];
4687 can_paste=true;
4688 copymap=currmap;
4689 copyscr=currscr;
4690 copyscrdata = zinit.screen_data[currmap*MAPSCRS+currscr];
4691 copyffc = -1;
4692 }
4693 }
4694
4695 void zmap::CopyFFC(int32_t n)
4696 {
4697 if(screens[currscr].valid&mVALID)
4698 {
4699 copy_mapscr(&copymapscr, &screens[currscr]);
4700 // Can't paste the screen itself
4701 can_paste = false;
4702 copymap=currmap;
4703 copyscr=currscr;
4704 copyffc = n;
4705 }
4706 }
4707
4708 void zmap::Paste(const mapscr& copymapscr)
4709 {
4710 if(can_paste)
4711 {
4712 int32_t oldcolor=getcolor();
4713
4714 if(!(screens[currscr].valid&mVALID))
4715 {
4716 screens[currscr].valid |= mVALID;
4717 screens[currscr].color = copymapscr.color;
4718 }
4719
4720 screens[currscr].door_combo_set = copymapscr.door_combo_set;
4721
4722 for(int32_t i=0; i<4; i++)
4723 {
4724 screens[currscr].door[i]=copymapscr.door[i];
4725 }
4726
4727 for(int32_t i=0; i<176; i++)
4728 {
4729 screens[currscr].data[i] = copymapscr.data[i];
4730 screens[currscr].cset[i] = copymapscr.cset[i];
4731 screens[currscr].sflag[i] = copymapscr.sflag[i];
4732 }
4733
4734 int32_t newcolor=getcolor();
4735 loadlvlpal(newcolor);
4736
4737 if(newcolor!=oldcolor)
4738 {
4739 rebuild_trans_table();
4740 }
4741
4742 saved=false;
4743 }
4744 }
4745
4746 void zmap::PasteUnderCombo(const mapscr& copymapscr)
4747 {
4748 if(can_paste)
4749 {
4750 screens[currscr].undercombo = copymapscr.undercombo;
4751 screens[currscr].undercset = copymapscr.undercset;
4752 saved=false;
4753 }
4754 }
4755
4756 void zmap::PasteSecretCombos(const mapscr& copymapscr)
4757 {
4758 if(can_paste)
4759 {
4760 for(int32_t i=0; i<128; i++)
4761 {
4762 screens[currscr].secretcombo[i] = copymapscr.secretcombo[i];
4763 screens[currscr].secretcset[i] = copymapscr.secretcset[i];
4764 screens[currscr].secretflag[i] = copymapscr.secretflag[i];
4765 }
4766
4767 saved=false;
4768 }
4769 }
4770
4771 // TODO const mapscr& copymapscr
4772 void zmap::PasteFFCombos(mapscr& copymapscr)
4773 {
4774 if(can_paste)
4775 {
4776 word c = copymapscr.numFFC();
4777 for(word i=0; i<c; i++)
4778 screens[currscr].ffcs[i] = copymapscr.ffcs[i];
4779 for(word i = c; i < MAXFFCS; ++i)
4780 screens[currscr].ffcs[i].clear();
4781
4782 saved=false;
4783 }
4784 }
4785
4786 void zmap::PasteWarps(const mapscr& copymapscr)
4787 {
4788 if(can_paste)
4789 {
4790 screens[currscr].sidewarpindex = copymapscr.sidewarpindex;
4791
4792 for(int32_t i=0; i<4; i++)
4793 {
4794 screens[currscr].tilewarptype[i] = copymapscr.tilewarptype[i];
4795 screens[currscr].tilewarpdmap[i] = copymapscr.tilewarpdmap[i];
4796 screens[currscr].tilewarpscr[i] = copymapscr.tilewarpscr[i];
4797 screens[currscr].sidewarptype[i] = copymapscr.sidewarptype[i];
4798 screens[currscr].sidewarpdmap[i] = copymapscr.sidewarpdmap[i];
4799 screens[currscr].sidewarpscr[i] = copymapscr.sidewarpscr[i];
4800 screens[currscr].flags2 &= ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4801 screens[currscr].flags2 |= copymapscr.flags2 & (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4802 screens[currscr].sidewarpoverlayflags = copymapscr.sidewarpoverlayflags;
4803 screens[currscr].tilewarpoverlayflags = copymapscr.tilewarpoverlayflags;
4804 }
4805
4806 saved=false;
4807 }
4808 }
4809
4810 void zmap::PasteScreenData(const mapscr& copymapscr)
4811 {
4812 if(can_paste)
4813 {
4814 screens[currscr].csensitive = copymapscr.csensitive;
4815 screens[currscr].oceansfx = copymapscr.oceansfx;
4816 screens[currscr].bosssfx = copymapscr.bosssfx;
4817 screens[currscr].secretsfx = copymapscr.secretsfx;
4818 screens[currscr].holdupsfx = copymapscr.holdupsfx;
4819 screens[currscr].flags = copymapscr.flags;
4820 screens[currscr].flags2 &= (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4821 screens[currscr].flags2 |= copymapscr.flags2 & ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4822 screens[currscr].flags3 = copymapscr.flags3;
4823 screens[currscr].flags4 = copymapscr.flags4;
4824 screens[currscr].flags5 = copymapscr.flags5;
4825 screens[currscr].flags6 = copymapscr.flags6;
4826 screens[currscr].flags7 = copymapscr.flags7;
4827 screens[currscr].flags8 = copymapscr.flags8;
4828 screens[currscr].flags9 = copymapscr.flags9;
4829 screens[currscr].flags10 = copymapscr.flags10;
4830 screens[currscr].item = copymapscr.item;
4831 screens[currscr].hasitem = copymapscr.hasitem;
4832 screens[currscr].itemx = copymapscr.itemx;
4833 screens[currscr].itemy = copymapscr.itemy;
4834 screens[currscr].nextmap = copymapscr.nextmap;
4835 screens[currscr].nextscr = copymapscr.nextscr;
4836 screens[currscr].nocarry = copymapscr.nocarry;
4837 screens[currscr].noreset = copymapscr.noreset;
4838 screens[currscr].path[0] = copymapscr.path[0];
4839 screens[currscr].path[1] = copymapscr.path[1];
4840 screens[currscr].path[2] = copymapscr.path[2];
4841 screens[currscr].path[3] = copymapscr.path[3];
4842 screens[currscr].pattern = copymapscr.pattern;
4843 screens[currscr].exitdir = copymapscr.exitdir;
4844 screens[currscr].enemyflags = copymapscr.enemyflags;
4845 screens[currscr].screen_midi = copymapscr.screen_midi;
4846 screens[currscr].stairx = copymapscr.stairx;
4847 screens[currscr].stairy = copymapscr.stairy;
4848 screens[currscr].timedwarptics = copymapscr.timedwarptics;
4849 saved=false;
4850 }
4851 }
4852
4853 void zmap::PasteWarpLocations(const mapscr& copymapscr)
4854 {
4855 if(can_paste)
4856 {
4857 screens[currscr].warpreturnc = copymapscr.warpreturnc;
4858 screens[currscr].warparrivalx = copymapscr.warparrivalx;
4859 screens[currscr].warparrivaly = copymapscr.warparrivaly;
4860
4861 for(int32_t i=0; i<4; i++)
4862 {
4863 screens[currscr].warpreturnx[i] = copymapscr.warpreturnx[i];
4864 screens[currscr].warpreturny[i] = copymapscr.warpreturny[i];
4865 }
4866
4867 saved=false;
4868 }
4869 }
4870
4871 void zmap::PasteDoors(const mapscr& copymapscr)
4872 {
4873 if(can_paste)
4874 {
4875 for(int32_t i=0; i<4; i++)
4876 screens[currscr].door[i] = copymapscr.door[i];
4877
4878 screens[currscr].door_combo_set = copymapscr.door_combo_set;
4879 saved=false;
4880 }
4881 }
4882
4883 void zmap::PasteLayers(const mapscr& copymapscr)
4884 {
4885 if(can_paste)
4886 {
4887 for(int32_t i=0; i<6; i++)
4888 {
4889 screens[currscr].layermap[i] = copymapscr.layermap[i];
4890 screens[currscr].layerscreen[i] = copymapscr.layerscreen[i];
4891 screens[currscr].layeropacity[i] = copymapscr.layeropacity[i];
4892 }
4893
4894 saved=false;
4895 }
4896 }
4897
4898 void zmap::PasteRoom(const mapscr& copymapscr)
4899 {
4900 if(can_paste)
4901 {
4902 screens[currscr].room = copymapscr.room;
4903 screens[currscr].catchall = copymapscr.catchall;
4904 saved=false;
4905 }
4906 }
4907
4908 void zmap::PasteGuy(const mapscr& copymapscr)
4909 {
4910 if(can_paste)
4911 {
4912 screens[currscr].guy = copymapscr.guy;
4913 screens[currscr].guytile = copymapscr.guytile;
4914 screens[currscr].guycs = copymapscr.guycs;
4915 SETFLAG(screens[currscr].roomflags,RFL_ALWAYS_GUY,copymapscr.roomflags&RFL_ALWAYS_GUY);
4916 SETFLAG(screens[currscr].roomflags,RFL_GUYFIRES,copymapscr.roomflags&RFL_GUYFIRES);
4917 screens[currscr].str = copymapscr.str;
4918 saved=false;
4919 }
4920 }
4921
4922 void zmap::PastePalette(const mapscr& copymapscr)
4923 {
4924 if(can_paste)
4925 {
4926 int32_t oldcolor=getcolor();
4927 screens[currscr].color = copymapscr.color;
4928 int32_t newcolor=getcolor();
4929 loadlvlpal(newcolor);
4930
4931 screens[currscr].valid|=mVALID;
4932
4933 if(newcolor!=oldcolor)
4934 {
4935 rebuild_trans_table();
4936 }
4937
4938 saved=false;
4939 }
4940 }
4941
4942 void zmap::PasteAll(const mapscr& copymapscr)
4943 {
4944 if(can_paste)
4945 {
4946 int32_t oldcolor=getcolor();
4947 copy_mapscr(&screens[currscr], &copymapscr);
4948 zinit.screen_data[currmap*MAPSCRS+currscr] = copyscrdata;
4949 //screens[currscr]=copymapscr;
4950 int32_t newcolor=getcolor();
4951 loadlvlpal(newcolor);
4952
4953 screens[currscr].valid|=mVALID;
4954
4955 if(newcolor!=oldcolor)
4956 {
4957 rebuild_trans_table();
4958 }
4959
4960 saved=false;
4961 }
4962 }
4963
4964
4965 void zmap::PasteToAll(const mapscr& copymapscr)
4966 {
4967 if(can_paste)
4968 {
4969 int32_t oldcolor=getcolor();
4970
4971 for(int32_t x=0; x<128; x++)
4972 {
4973 if(!(screens[x].valid&mVALID))
4974 {
4975 screens[x].valid |= mVALID;
4976 screens[x].color = copymapscr.color;
4977 }
4978
4979 for(int32_t i=0; i<176; i++)
4980 {
4981 screens[x].data[i] = copymapscr.data[i];
4982 screens[x].cset[i] = copymapscr.cset[i];
4983 screens[x].sflag[i] = copymapscr.sflag[i];
4984 }
4985 }
4986
4987 int32_t newcolor=getcolor();
4988 loadlvlpal(newcolor);
4989
4990 if(!(screens[currscr].valid&mVALID))
4991 {
4992 newcolor=-1;
4993 }
4994
4995 if(newcolor!=oldcolor)
4996 {
4997 rebuild_trans_table();
4998 }
4999
5000 saved=false;
5001 }
5002 }
5003
5004 void zmap::PasteAllToAll(const mapscr& copymapscr)
5005 {
5006 if(can_paste)
5007 {
5008 int32_t oldcolor=getcolor();
5009
5010 for(int32_t x=0; x<128; x++)
5011 {
5012 copy_mapscr(&screens[x], &copymapscr);
5013 zinit.screen_data[currmap*MAPSCRS+x] = copyscrdata;
5014 //screens[x]=copymapscr;
5015 }
5016
5017 int32_t newcolor=getcolor();
5018 loadlvlpal(newcolor);
5019
5020 if(!(screens[currscr].valid&mVALID))
5021 {
5022 newcolor=-1;
5023 }
5024
5025 if(newcolor!=oldcolor)
5026 {
5027 rebuild_trans_table();
5028 }
5029
5030 saved=false;
5031 }
5032 }
5033
5034 void zmap::PasteEnemies(const mapscr& copymapscr)
5035 {
5036 if(can_paste)
5037 {
5038 for(int32_t i=0; i<10; i++)
5039 screens[currscr].enemy[i]=copymapscr.enemy[i];
5040 }
5041 }
5042
5043 void zmap::setCopyFFC(int32_t n)
5044 {
5045 copyffc = n;
5046 }
5047
5048 void zmap::update_combo_cycling()
5049 {
5050 if(!prv_mode||!prv_cmbcycle)
5051 {
5052 return;
5053 }
5054
5055 int32_t x;
5056 int32_t newdata[176];
5057 int32_t newcset[176];
5058 bool restartanim[MAXCOMBOS] = {0};
5059
5060 for(int32_t i=0; i<176; i++)
5061 {
5062 newdata[i]=-1;
5063 newcset[i]=-1;
5064
5065 x=prvscr.data[i];
5066
5067 //time to restart
5068 if((combobuf[x].aclk>=combobuf[x].speed) &&
5069 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5070 (combobuf[x].nextcombo!=0))
5071 {
5072 newdata[i]=combobuf[x].nextcombo;
5073 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5074 newcset[i]=combobuf[x].nextcset;
5075 int32_t c = newdata[i];
5076
5077 if(combobuf[c].animflags & AF_CYCLE)
5078 {
5079 restartanim[c]=true;
5080 }
5081 }
5082 }
5083
5084 for(int32_t i=0; i<176; i++)
5085 {
5086 x=prvscr.data[i];
5087
5088 //time to restart
5089 if((combobuf[x].aclk>=combobuf[x].speed) &&
5090 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5091 (combobuf[x].nextcombo!=0))
5092 {
5093 newdata[i]=combobuf[x].nextcombo;
5094 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5095 newcset[i]=combobuf[x].nextcset;
5096 int32_t c = newdata[i];
5097
5098 if(combobuf[c].animflags & AF_CYCLE)
5099 {
5100 restartanim[c]=true;
5101 }
5102 }
5103 }
5104
5105 for(int32_t i=0; i<176; i++)
5106 {
5107 if(newdata[i]==-1)
5108 continue;
5109
5110 prvscr.data[i]=newdata[i];
5111 prvscr.cset[i]=newcset[i];
5112 }
5113
5114 word maxffc = prvscr.numFFC();
5115 for(word i=0; i<maxffc; i++)
5116 {
5117 ffcdata& ffc = prvscr.ffcs[i];
5118 newcombo const& cmb = combobuf[ffc.data];
5119
5120 //time to restart
5121 if((cmb.aclk>=cmb.speed) &&
5122 (cmb.tile-cmb.frames>=cmb.o_tile-1) &&
5123 (cmb.nextcombo!=0))
5124 {
5125 ffc.data = cmb.nextcombo;
5126 if(!(cmb.animflags & AF_CYCLENOCSET))
5127 ffc.cset=cmb.nextcset;
5128
5129 if(combobuf[ffc.data].animflags & AF_CYCLE)
5130 {
5131 restartanim[ffc.data]=true;
5132 }
5133 prvscr.ffcs[i].data = ffc.data;
5134 prvscr.ffcs[i].cset=ffc.cset;
5135 }
5136 }
5137
5138
5139 if(get_qr(qr_CMBCYCLELAYERS))
5140 {
5141 for(int32_t j=0; j<6; j++)
5142 {
5143 if(!prvlayers[j].valid)
5144 continue;
5145
5146 for(int32_t i=0; i<176; i++)
5147 {
5148 newdata[i]=-1;
5149 newcset[i]=-1;
5150
5151 x=(prvlayers[j]).data[i];
5152
5153 //time to restart
5154 if((combobuf[x].aclk>=combobuf[x].speed) &&
5155 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5156 (combobuf[x].nextcombo!=0))
5157 {
5158 newdata[i]=combobuf[x].nextcombo;
5159 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5160 newcset[i]=combobuf[x].nextcset;
5161 int32_t c = newdata[i];
5162
5163 if(combobuf[c].animflags & AF_CYCLE)
5164 {
5165 restartanim[c]=true;
5166 }
5167 }
5168 }
5169
5170 for(int32_t i=0; i<176; i++)
5171 {
5172 x=(prvlayers[j]).data[i];
5173
5174 //time to restart
5175 if((combobuf[x].aclk>=combobuf[x].speed) &&
5176 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5177 (combobuf[x].nextcombo!=0))
5178 {
5179 newdata[i]=combobuf[x].nextcombo;
5180 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5181 newcset[i]=combobuf[x].nextcset;
5182 int32_t c = newdata[i];
5183
5184 if(combobuf[c].animflags & AF_CYCLE)
5185 {
5186 restartanim[c]=true;
5187 }
5188 }
5189 }
5190
5191 for(int32_t i=0; i<176; i++)
5192 {
5193 if(newdata[i]==-1)
5194 continue;
5195
5196 prvlayers[j].data[i]=newdata[i];
5197 prvlayers[j].cset[i]=newcset[i];
5198 }
5199 }
5200 }
5201
5202 for(int32_t i=0; i<MAXCOMBOS; i++)
5203 {
5204 if(restartanim[i])
5205 {
5206 combobuf[i].tile = combobuf[i].o_tile;
5207 combobuf[i].cur_frame=0;
5208 combobuf[i].aclk = 0;
5209 }
5210 }
5211 }
5212
5213 void zmap::update_freeform_combos()
5214 {
5215 if(!prv_mode||!prv_cmbcycle)
5216 {
5217 return;
5218 }
5219
5220 // TODO: this changer code is a duplicated here and for zplayer. Should fix that.
5221 word maxffc = prvscr.numFFC();
5222 for(int32_t i=0; i<maxffc; i++)
5223 {
5224 if(!(prvscr.ffcs[i].flags&ffCHANGER) && prvscr.ffcs[i].data!=0 && !(prvscr.ffcs[i].flags&ffSTATIONARY))
5225 {
5226 for(int32_t j=0; j<maxffc; j++)
5227 {
5228 if(i!=j)
5229 {
5230 if(prvscr.ffcs[j].flags&ffCHANGER && prvscr.ffcs[j].data != 0)
5231 {
5232 if((((prvscr.ffcs[j].x.getInt())!=ffposx[i])||((prvscr.ffcs[j].y.getInt())!=ffposy[i]))&&(prvscr.ffcs[i].link==0))
5233 {
5234 if((isonline(prvscr.ffcs[i].x.getZLong(),prvscr.ffcs[i].y.getZLong(),ffprvx[i],ffprvy[i],prvscr.ffcs[j].x.getZLong(),prvscr.ffcs[j].y.getZLong())||
5235 ((prvscr.ffcs[i].x.getZLong()==prvscr.ffcs[j].x.getZLong())&&(prvscr.ffcs[i].y.getZLong()==prvscr.ffcs[j].y.getZLong())))&&(ffprvx[i]>-10000000&&ffprvy[i]>-10000000))
5236 {
5237 //prvscr.ffcs[i].data=prvscr.ffcs[j].data;
5238 //prvscr.ffcs[i].cset=prvscr.ffcs[j].cset;
5239 if(prvscr.ffcs[j].flags&ffCHANGETHIS)
5240 {
5241 prvscr.ffcs[i].data = prvscr.ffcs[j].data;
5242 prvscr.ffcs[i].cset = prvscr.ffcs[j].cset;
5243 }
5244
5245 if(prvscr.ffcs[j].flags&ffCHANGENEXT)
5246 prvscr.ffcs[i].data += 1;
5247
5248 if(prvscr.ffcs[j].flags&ffCHANGEPREV)
5249 prvscr.ffcs[i].data -= 1;
5250
5251 prvscr.ffcs[i].delay=prvscr.ffcs[j].delay;
5252 prvscr.ffcs[i].x=prvscr.ffcs[j].x;
5253 prvscr.ffcs[i].y=prvscr.ffcs[j].y;
5254
5255 prvscr.ffcs[i].vx=prvscr.ffcs[j].vx;
5256 prvscr.ffcs[i].vy=prvscr.ffcs[j].vy;
5257 prvscr.ffcs[i].ax=prvscr.ffcs[j].ax;
5258 prvscr.ffcs[i].ay=prvscr.ffcs[j].ay;
5259
5260 prvscr.ffcs[i].link=prvscr.ffcs[j].link;
5261 prvscr.ffcs[i].hit_width=prvscr.ffcs[j].hit_width;
5262 prvscr.ffcs[i].hit_height=prvscr.ffcs[j].hit_height;
5263 prvscr.ffcs[i].txsz=prvscr.ffcs[j].txsz;
5264 prvscr.ffcs[i].tysz=prvscr.ffcs[j].tysz;
5265
5266 if(prvscr.ffcs[i].flags&ffCARRYOVER)
5267 prvscr.ffcs[i].flags=prvscr.ffcs[j].flags&ffCARRYOVER;
5268 else prvscr.ffcs[i].flags=prvscr.ffcs[j].flags;
5269
5270 prvscr.ffcs[i].flags&=~ffCHANGER;
5271 ffposx[i]=(prvscr.ffcs[j].x.getInt());
5272 ffposy[i]=(prvscr.ffcs[j].y.getInt());
5273
5274 if(combobuf[prvscr.ffcs[j].data].flag>15 && combobuf[prvscr.ffcs[j].data].flag<32)
5275 {
5276 prvscr.ffcs[j].data = prvscr.secretcombo[combobuf[prvscr.ffcs[j].data].flag - 16 + 4];
5277 }
5278
5279 if((prvscr.ffcs[j].flags&ffSWAPNEXT)||(prvscr.ffcs[j].flags&ffSWAPPREV))
5280 {
5281 int32_t k=0;
5282
5283 if(prvscr.ffcs[j].flags&ffSWAPNEXT)
5284 k=j<(MAXFFCS-1)?j+1:0;
5285
5286 if(prvscr.ffcs[j].flags&ffSWAPPREV)
5287 k=j>0?j-1:(MAXFFCS-1);
5288
5289 zc_swap(prvscr.ffcs[j].vx,prvscr.ffcs[k].vx);
5290 zc_swap(prvscr.ffcs[j].vy,prvscr.ffcs[k].vy);
5291 zc_swap(prvscr.ffcs[j].ax,prvscr.ffcs[k].ax);
5292 zc_swap(prvscr.ffcs[j].ay,prvscr.ffcs[k].ay);
5293 zc_swap(prvscr.ffcs[j].link,prvscr.ffcs[k].link);
5294 zc_swap(prvscr.ffcs[j].hit_width,prvscr.ffcs[k].hit_width);
5295 zc_swap(prvscr.ffcs[j].hit_height,prvscr.ffcs[k].hit_height);
5296 zc_swap(prvscr.ffcs[j].txsz,prvscr.ffcs[k].txsz);
5297 zc_swap(prvscr.ffcs[j].tysz,prvscr.ffcs[k].tysz);
5298 zc_swap(prvscr.ffcs[j].flags,prvscr.ffcs[k].flags);
5299 }
5300 }
5301 }
5302 }
5303 }
5304 }
5305
5306 if(prvscr.ffcs[i].link ? !prvscr.ffcs[prvscr.ffcs[i].link].delay : !prvscr.ffcs[i].delay)
5307 {
5308 if(prvscr.ffcs[i].link&&(prvscr.ffcs[i].link-1)!=i)
5309 {
5310 ffprvx[i] = prvscr.ffcs[i].x.getZLong();
5311 ffprvy[i] = prvscr.ffcs[i].y.getZLong();
5312 prvscr.ffcs[i].x+=prvscr.ffcs[prvscr.ffcs[i].link-1].vx;
5313 prvscr.ffcs[i].y+=prvscr.ffcs[prvscr.ffcs[i].link-1].vy;
5314 }
5315 else
5316 {
5317 ffprvx[i] = prvscr.ffcs[i].x.getZLong();
5318 ffprvy[i] = prvscr.ffcs[i].y.getZLong();
5319 prvscr.ffcs[i].x+=prvscr.ffcs[i].vx;
5320 prvscr.ffcs[i].y+=prvscr.ffcs[i].vy;
5321 prvscr.ffcs[i].vx+=prvscr.ffcs[i].ax;
5322 prvscr.ffcs[i].vy+=prvscr.ffcs[i].ay;
5323
5324 if(get_qr(qr_OLD_FFC_SPEED_CAP))
5325 {
5326 if(prvscr.ffcs[i].vx>128) prvscr.ffcs[i].vx=128;
5327
5328 if(prvscr.ffcs[i].vx<-128) prvscr.ffcs[i].vx=-128;
5329
5330 if(prvscr.ffcs[i].vy>128) prvscr.ffcs[i].vy=128;
5331
5332 if(prvscr.ffcs[i].vy<-128) prvscr.ffcs[i].vy=-128;
5333 }
5334 }
5335 }
5336 else
5337 {
5338 if(!prvscr.ffcs[i].link || (prvscr.ffcs[i].link-1)==i)
5339 prvscr.ffcs[i].delay--;
5340 }
5341
5342 if(prvscr.ffcs[i].x<-32)
5343 {
5344 if(prvscr.flags6&fWRAPAROUNDFF)
5345 {
5346 prvscr.ffcs[i].x = (288+(prvscr.ffcs[i].x+32));
5347 ffprvy[i] = prvscr.ffcs[i].y.getZLong();
5348 }
5349 else
5350 {
5351 prvscr.ffcs[i].data = 0;
5352 prvscr.ffcs[i].flags&=~ffCARRYOVER;
5353 }
5354 }
5355
5356 if(prvscr.ffcs[i].y<-32)
5357 {
5358 if(prvscr.flags6&fWRAPAROUNDFF)
5359 {
5360 prvscr.ffcs[i].y = 208+(prvscr.ffcs[i].y+32);
5361 ffprvx[i] = prvscr.ffcs[i].x.getZLong();
5362 }
5363 else
5364 {
5365 prvscr.ffcs[i].data = 0;
5366 prvscr.ffcs[i].flags&=~ffCARRYOVER;
5367 }
5368 }
5369
5370 if(prvscr.ffcs[i].x>=288)
5371 {
5372 if(prvscr.flags6&fWRAPAROUNDFF)
5373 {
5374 prvscr.ffcs[i].x = prvscr.ffcs[i].x-288-32;
5375 ffprvy[i] = prvscr.ffcs[i].y.getZLong();
5376 }
5377 else
5378 {
5379 prvscr.ffcs[i].data = 0;
5380 prvscr.ffcs[i].flags&=~ffCARRYOVER;
5381 }
5382 }
5383
5384 if(prvscr.ffcs[i].y>=208)
5385 {
5386 if(prvscr.flags6&fWRAPAROUNDFF)
5387 {
5388 prvscr.ffcs[i].y = prvscr.ffcs[i].y-208-32;
5389 ffprvy[i] = prvscr.ffcs[i].x.getZLong();
5390 }
5391 else
5392 {
5393 prvscr.ffcs[i].data = 0;
5394 prvscr.ffcs[i].flags&=~ffCARRYOVER;
5395 }
5396 }
5397
5398 }
5399 }
5400 }
5401
5402 void zmap::goto_dmapscr(int dmap, int scr)
5403 {
5404 setCurrMap(DMaps[dmap].map);
5405 setCurrScr(scr+DMaps[dmap].xoff);
5406 }
5407 void zmap::goto_mapscr(int map, int scr)
5408 {
5409 setCurrMap(map);
5410 setCurrScr(scr);
5411 }
5412
5413 void zmap::dowarp(int32_t type, int32_t index)
5414 {
5415 set_warpback();
5416 if(type==0)
5417 {
5418
5419 int32_t dmap=screens[currscr].tilewarpdmap[index];
5420 int32_t scr=screens[currscr].tilewarpscr[index];
5421
5422 switch(screens[currscr].tilewarptype[index])
5423 {
5424 case wtCAVE:
5425 case wtNOWARP:
5426 break;
5427
5428 default:
5429 goto_dmapscr(dmap, scr);
5430 break;
5431 }
5432 }
5433 else if(type==1)
5434 {
5435 int32_t dmap=screens[currscr].sidewarpdmap[index];
5436 int32_t scr=screens[currscr].sidewarpscr[index];
5437
5438 switch(screens[currscr].sidewarptype[index])
5439 {
5440 case wtCAVE:
5441 case wtNOWARP:
5442 break;
5443
5444 default:
5445 goto_dmapscr(dmap, scr);
5446 break;
5447 }
5448 }
5449 }
5450
5451 extern int32_t prv_twon;
5452
5453 void zmap::prv_dowarp(int32_t type, int32_t index)
5454 {
5455 if(type==0)
5456 {
5457
5458 int32_t dmap=prvscr.tilewarpdmap[index];
5459 int32_t scr=prvscr.tilewarpscr[index];
5460
5461 switch(prvscr.tilewarptype[index])
5462 {
5463 case wtCAVE:
5464 case wtNOWARP:
5465 break;
5466
5467 default:
5468 //setCurrMap(DMaps[dmap].map);
5469 //setCurrScr(scr+DMaps[dmap].xoff);
5470 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5471 loadlvlpal(getcolor());
5472 rebuild_trans_table();
5473 //prv_cmbcycle=0;
5474 break;
5475 }
5476 }
5477 else if(type==1)
5478 {
5479 int32_t dmap=prvscr.sidewarpdmap[index];
5480 int32_t scr=prvscr.sidewarpscr[index];
5481
5482 switch(prvscr.sidewarptype[index])
5483 {
5484 case wtCAVE:
5485 case wtNOWARP:
5486 break;
5487
5488 default:
5489 //setCurrMap(DMaps[dmap].map);
5490 //setCurrScr(scr+DMaps[dmap].xoff);
5491 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5492 loadlvlpal(getcolor());
5493 rebuild_trans_table();
5494 //prv_cmbcycle=0;
5495 break;
5496 }
5497 }
5498
5499 if(prv_twon)
5500 {
5501 prv_time=get_prvscr()->timedwarptics;
5502 }
5503
5504 //also reset FFC information (so that changers will work correctly) -DD
5505 memset(ffposx,0xFF,sizeof(int16_t)*32);
5506 memset(ffposy,0xFF,sizeof(int16_t)*32);
5507 memset(ffprvx,0xFF,sizeof(float)*32);
5508 memset(ffprvy,0xFF,sizeof(float)*32);
5509 }
5510
5511 void zmap::dowarp2(int32_t ring,int32_t index)
5512 {
5513 set_warpback();
5514 goto_dmapscr(QMisc.warp[ring].dmap[index], QMisc.warp[ring].scr[index]);
5515 }
5516
5517 void zmap::set_warpback()
5518 {
5519 warpbackmap = currmap;
5520 warpbackscreen = currscr;
5521 }
5522 bool zmap::has_warpback()
5523 {
5524 return warpbackmap && warpbackscreen
5525 && !(warpbackmap == currmap && warpbackscreen == currscr);
5526 }
5527 void zmap::warpback()
5528 {
5529 if(!has_warpback())
5530 return;
5531 int m = currmap, s = currscr;
5532 goto_mapscr(*warpbackmap, *warpbackscreen);
5533 warpbackmap = m;
5534 warpbackscreen = s;
5535 }
5536
5537 /******************************/
5538 /******** ZQuest stuff ********/
5539 /******************************/
5540
5541 bool save_msgstrs(const char *path)
5542 {
5543 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5544
5545 if(!f)
5546 {
5547 return false;
5548 }
5549
5550 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)==0)
5551 {
5552 pack_fclose(f);
5553 return true;
5554 }
5555
5556 pack_fclose(f);
5557 return false;
5558 }
5559
5560 1 bool save_strings_tsv(const char *path)
5561 {
5562 1 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5563
5564
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(!f)
5565 {
5566 return false;
5567 }
5568
5569
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(writestrings_tsv(f)==0)
5570 {
5571 1 pack_fclose(f);
5572 1 return true;
5573 }
5574
5575 pack_fclose(f);
5576 return false;
5577 1 }
5578
5579 bool save_msgstrs_text(const char *path)
5580 {
5581 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5582
5583 if(!f)
5584 {
5585 return false;
5586 }
5587
5588 if(writestrings_text(f)==0)
5589 {
5590 pack_fclose(f);
5591 return true;
5592 }
5593
5594 pack_fclose(f);
5595 return false;
5596 }
5597
5598 bool load_msgstrs(const char *path, int32_t startstring)
5599 {
5600 //these are here to bypass compiler warnings about unused arguments
5601 startstring=startstring;
5602
5603 dword section_id;
5604 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5605
5606 if(!f)
5607 {
5608 return false;
5609 }
5610
5611 if(!p_mgetl(&section_id,f))
5612 {
5613 return false;
5614 }
5615
5616 if(section_id==ID_STRINGS)
5617 {
5618 if(readstrings(f, &header)==0)
5619 {
5620 pack_fclose(f);
5621 return true;
5622 }
5623 else
5624 {
5625 pack_fclose(f);
5626 return false;
5627 }
5628 }
5629
5630 pack_fclose(f);
5631 return false;
5632 }
5633
5634 bool load_strings_tsv(const char *path)
5635 {
5636 try
5637 {
5638 parse_strings_tsv(util::read_text_file(path));
5639 }
5640 catch (std::exception& ex)
5641 {
5642 InfoDialog("Import .tsv Error", ex.what()).show();
5643 return false;
5644 }
5645 return true;
5646 }
5647
5648 bool save_pals(const char *path)
5649 {
5650 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5651
5652 if(!f)
5653 {
5654 return false;
5655 }
5656
5657 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)==0)
5658 {
5659 pack_fclose(f);
5660 return true;
5661 }
5662
5663 pack_fclose(f);
5664 return false;
5665 }
5666
5667 bool load_pals(const char *path, int32_t startcset)
5668 {
5669 dword section_id;
5670 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5671
5672 if(!f)
5673 {
5674 return false;
5675 }
5676
5677 if(!p_mgetl(&section_id,f))
5678 {
5679 return false;
5680 }
5681
5682 if(section_id==ID_CSETS)
5683 {
5684 if(readcolordata(f, &QMisc, 0x250, 33, startcset, newerpdTOTAL-startcset)==0)
5685 {
5686 pack_fclose(f);
5687 loadlvlpal(Color);
5688 return true;
5689 }
5690 else
5691 {
5692 pack_fclose(f);
5693 return false;
5694 }
5695 }
5696
5697 return false;
5698 }
5699
5700 bool save_dmaps(const char *path)
5701 {
5702 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5703
5704 if(!f)
5705 {
5706 return false;
5707 }
5708
5709 if(writedmaps(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXDMAPS)==0)
5710 {
5711 pack_fclose(f);
5712 return true;
5713 }
5714
5715 pack_fclose(f);
5716 return false;
5717 }
5718
5719 bool load_dmaps(const char *path, int32_t startdmap)
5720 {
5721 dword section_id;
5722 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5723
5724 if(!f)
5725 {
5726 return false;
5727 }
5728
5729 if(!p_mgetl(&section_id,f))
5730 {
5731 return false;
5732 }
5733
5734 if(section_id==ID_DMAPS)
5735 {
5736 if(readdmaps(f, NULL, 0x250, 33, startdmap, MAXDMAPS-startdmap)==0)
5737 {
5738 pack_fclose(f);
5739 return true;
5740 }
5741 else
5742 {
5743 pack_fclose(f);
5744 return false;
5745 }
5746 }
5747
5748 return false;
5749 }
5750 bool save_combos(const char *path)
5751 {
5752 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5753
5754 if(!f)
5755 {
5756 return false;
5757 }
5758
5759 reset_combo_animations();
5760 reset_combo_animations2();
5761
5762 if(writecombos(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)==0)
5763 {
5764 pack_fclose(f);
5765 return true;
5766 }
5767
5768 pack_fclose(f);
5769 return false;
5770 }
5771
5772 bool load_combos(const char *path, int32_t startcombo)
5773 {
5774 dword section_id;
5775 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5776
5777 if(!f)
5778 {
5779 return false;
5780 }
5781
5782 if(!p_mgetl(&section_id,f))
5783 {
5784 return false;
5785 }
5786
5787 if(section_id==ID_COMBOS)
5788 {
5789 if(readcombos(f, NULL, 0x250, 33, startcombo, MAXCOMBOS-startcombo)==0)
5790 {
5791 pack_fclose(f);
5792 return true;
5793 }
5794 else
5795 {
5796 pack_fclose(f);
5797 // init_combos(true, &header);
5798 return false;
5799 }
5800 }
5801
5802 return false;
5803 }
5804
5805 bool save_tiles(const char *path)
5806 {
5807 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5808
5809 if(!f)
5810 {
5811 return false;
5812 }
5813
5814 // reset_combo_animations();
5815 if(writetiles(f, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES)==0)
5816 {
5817 pack_fclose(f);
5818 return true;
5819 }
5820
5821 pack_fclose(f);
5822 return false;
5823 }
5824
5825 bool load_tiles(const char *path, int32_t starttile)
5826 {
5827 dword section_id;
5828 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5829
5830 if(!f)
5831 {
5832 return false;
5833 }
5834
5835 if(!p_mgetl(&section_id,f))
5836 {
5837 return false;
5838 }
5839
5840 if(section_id==ID_TILES)
5841 {
5842 if(readtiles(f, newtilebuf, NULL, 0x250, 33, starttile, NEWMAXTILES-starttile, false)==0)
5843 {
5844 pack_fclose(f);
5845 return true;
5846 }
5847 else
5848 {
5849 pack_fclose(f);
5850 init_tiles(true, &header);
5851 return false;
5852 }
5853 }
5854
5855 return false;
5856 }
5857
5858 int32_t writeguys(PACKFILE *f, zquestheader *Header);
5859 bool save_guys(const char *path)
5860 {
5861 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5862
5863 if(!f)
5864 {
5865 return false;
5866 }
5867
5868 /*
5869 int32_t id = ID_GUYS;
5870 if(!p_mputl(id,f))
5871 {
5872 return false;
5873 }
5874 */
5875
5876 zquestheader h;
5877 h.zelda_version = 0x250;
5878 h.build = 21;
5879
5880 if(writeguys(f, &h)==0)
5881 {
5882 pack_fclose(f);
5883 return true;
5884 }
5885
5886 pack_fclose(f);
5887 return false;
5888 }
5889
5890 bool load_guys(const char *path)
5891 {
5892 dword section_id;
5893 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5894
5895 if(!f)
5896 {
5897 return false;
5898 }
5899
5900 if(!p_mgetl(&section_id,f))
5901 {
5902 pack_fclose(f);
5903 return false;
5904 }
5905
5906 zquestheader h;
5907 h.zelda_version = 0x250;
5908 h.build = 21;
5909
5910 if(section_id==ID_GUYS)
5911 {
5912 if(readguys(f, &h)==0)
5913 {
5914 pack_fclose(f);
5915 return true;
5916 }
5917 }
5918
5919 pack_fclose(f);
5920 return false;
5921 }
5922
5923
5924 //int32_t writeguys(PACKFILE *f, zquestheader *Header);
5925 bool save_combo_alias(const char *path)
5926 {
5927 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5928
5929 if(!f)
5930 {
5931 return false;
5932 }
5933
5934 zquestheader h;
5935 h.zelda_version = 0x250;
5936 h.build = 21;
5937
5938 if(writecomboaliases(f, 0, 0)==0)
5939 {
5940 pack_fclose(f);
5941 return true;
5942 }
5943
5944 pack_fclose(f);
5945 return false;
5946 }
5947
5948 bool load_combo_alias(const char *path)
5949 {
5950 dword section_id;
5951 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5952
5953 if(!f)
5954 {
5955 return false;
5956 }
5957
5958 if(!p_mgetl(&section_id,f))
5959 {
5960 pack_fclose(f);
5961 return false;
5962 }
5963
5964 zquestheader h;
5965 h.zelda_version = 0x250;
5966 h.build = 21;
5967
5968 if(section_id==ID_COMBOALIASES)
5969 {
5970 if(readcomboaliases(f, &h, 0, 0)==0)
5971 {
5972 pack_fclose(f);
5973 return true;
5974 }
5975 }
5976
5977 pack_fclose(f);
5978 return false;
5979 }
5980
5981 bool load_zgp(const char *path)
5982 {
5983 dword section_id;
5984 dword section_version;
5985 dword section_cversion;
5986 // setPackfilePassword(NULL);
5987 PACKFILE *f=pack_fopen_password(path,F_READ,"");
5988
5989 if(!f)
5990 return false;
5991
5992 if(!p_mgetl(&section_id,f))
5993 {
5994 pack_fclose(f);
5995 return false;
5996 }
5997
5998 if(section_id!=ID_GRAPHICSPACK)
5999 {
6000 pack_fclose(f);
6001 return false;
6002 }
6003
6004 //section version info
6005 if(!p_igetw(&section_version,f))
6006 {
6007 return 2;
6008 }
6009
6010 if(!p_igetw(&section_cversion,f))
6011 {
6012 return 3;
6013 }
6014
6015 //tiles
6016 if(!p_mgetl(&section_id,f))
6017 {
6018 pack_fclose(f);
6019 return false;
6020 }
6021
6022 if(section_id==ID_TILES)
6023 {
6024 if(readtiles(f, newtilebuf, NULL, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES, false)!=0)
6025 {
6026 pack_fclose(f);
6027 init_tiles(true, &header);
6028 return false;
6029 }
6030 }
6031 else
6032 {
6033 pack_fclose(f);
6034 return false;
6035 }
6036
6037 //combos
6038 if(!p_mgetl(&section_id,f))
6039 {
6040 pack_fclose(f);
6041 return false;
6042 }
6043
6044 if(section_id==ID_COMBOS)
6045 {
6046 if(readcombos(f, NULL, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
6047 {
6048 pack_fclose(f);
6049 // init_combos(true, &header);
6050 return false;
6051 }
6052 }
6053 else
6054 {
6055 pack_fclose(f);
6056 return false;
6057 }
6058
6059 //palettes
6060 if(!p_mgetl(&section_id,f))
6061 {
6062 pack_fclose(f);
6063 return false;
6064 }
6065
6066 if(section_id==ID_CSETS)
6067 {
6068 if(readcolordata(f, &QMisc, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
6069 {
6070 pack_fclose(f);
6071 return false;
6072 }
6073 }
6074 else
6075 {
6076 pack_fclose(f);
6077 return false;
6078 }
6079
6080 //items
6081 if(!p_mgetl(&section_id,f))
6082 {
6083 pack_fclose(f);
6084 return false;
6085 }
6086
6087 if(section_id==ID_ITEMS)
6088 {
6089 if(readitems(f, ZELDA_VERSION, VERSION_BUILD)!=0)
6090 {
6091 pack_fclose(f);
6092 return false;
6093 }
6094 }
6095 else
6096 {
6097 pack_fclose(f);
6098 return false;
6099 }
6100
6101 //weapons
6102 if(!p_mgetl(&section_id,f))
6103 {
6104 pack_fclose(f);
6105 return false;
6106 }
6107
6108 if(section_id==ID_WEAPONS)
6109 {
6110 if(readweapons(f, &header)!=0)
6111 {
6112 pack_fclose(f);
6113 return false;
6114 }
6115 }
6116 else
6117 {
6118 pack_fclose(f);
6119 return false;
6120 }
6121
6122 //read the triforce pieces info and make sure it worked
6123 //really do this?
6124
6125 //read the game icons info and make sure it worked
6126 if(!p_mgetl(&section_id,f))
6127 {
6128 pack_fclose(f);
6129 return false;
6130 }
6131
6132 if(section_id==ID_ICONS)
6133 {
6134 if(readgameicons(f, &header, &QMisc)!=0)
6135 {
6136 pack_fclose(f);
6137 return false;
6138 }
6139 }
6140 else
6141 {
6142 pack_fclose(f);
6143 return false;
6144 }
6145
6146 //read the misc colors info and map styles info and make sure it worked
6147 if(!p_mgetl(&section_id,f))
6148 {
6149 pack_fclose(f);
6150 return false;
6151 }
6152
6153 if(section_id==ID_COLORS)
6154 {
6155 if(readmisccolors(f, &header, &QMisc)!=0)
6156 {
6157 pack_fclose(f);
6158 return false;
6159 }
6160 }
6161 else
6162 {
6163 pack_fclose(f);
6164 return false;
6165 }
6166
6167 //read the door combo sets and make sure it worked
6168 if(!p_mgetl(&section_id,f))
6169 {
6170 pack_fclose(f);
6171 return false;
6172 }
6173
6174 if(section_id==ID_DOORS)
6175 {
6176 if(readdoorcombosets(f, &header)!=0)
6177 {
6178 pack_fclose(f);
6179 return false;
6180 }
6181 }
6182 else
6183 {
6184 pack_fclose(f);
6185 return false;
6186 }
6187
6188 //read the template screens and make sure it worked
6189 //really do this?
6190
6191 //yay! it worked! close the file and say everything was ok.
6192 loadlvlpal(Color);
6193 setup_combo_animations();
6194 setup_combo_animations2();
6195 pack_fclose(f);
6196 return true;
6197 }
6198
6199 bool save_zgp(const char *path)
6200 {
6201 // jwin_alert("Error","This feature not yet implemented.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
6202 // return false;
6203 reset_combo_animations();
6204 reset_combo_animations2();
6205
6206 //open the file
6207 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6208
6209 if(!f)
6210 return false;
6211
6212 dword section_id=ID_GRAPHICSPACK;
6213 dword section_version=V_GRAPHICSPACK;
6214 dword section_cversion=CV_GRAPHICSPACK;
6215
6216 //section id
6217 if(!p_mputl(section_id,f))
6218 {
6219 return 1;
6220 }
6221
6222 //section version info
6223 if(!p_iputw(section_version,f))
6224 {
6225 return 2;
6226 }
6227
6228 if(!p_iputw(section_cversion,f))
6229 {
6230 return 3;
6231 }
6232
6233 //tiles
6234 if(writetiles(f, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES)!=0)
6235 {
6236 pack_fclose(f);
6237 return false;
6238 }
6239
6240 //combos
6241 if(writecombos(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
6242 {
6243 pack_fclose(f);
6244 return false;
6245 }
6246
6247 //palettes
6248 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
6249 {
6250 pack_fclose(f);
6251 return false;
6252 }
6253
6254 //items
6255 if(writeitems(f, &header)!=0)
6256 {
6257 pack_fclose(f);
6258 return false;
6259 }
6260
6261 //weapons
6262 if(writeweapons(f, &header)!=0)
6263 {
6264 pack_fclose(f);
6265 return false;
6266 }
6267
6268 //write the triforce pieces info and make sure it worked
6269 //really do this?
6270
6271 //write the game icons info and make sure it worked
6272 if(writegameicons(f, &header)!=0)
6273 {
6274 pack_fclose(f);
6275 return false;
6276 }
6277
6278 //write the misc colors info and map styles info and make sure it worked
6279 if(writemisccolors(f, &header)!=0)
6280 {
6281 pack_fclose(f);
6282 return false;
6283 }
6284
6285 //write the door combo sets and make sure it worked
6286 if(writedoorcombosets(f, &header)!=0)
6287 {
6288 pack_fclose(f);
6289 return false;
6290 }
6291
6292 //write the template screens and make sure it worked
6293 //really do this?
6294
6295 pack_fclose(f);
6296 return true;
6297 }
6298
6299 bool save_subscreen(const char *path, ZCSubscreen const& savefrom)
6300 {
6301 //open the file
6302 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6303
6304 if(!f)
6305 return false;
6306
6307 dword section_id=ID_SUBSCREEN;
6308 dword s_version=V_SUBSCREEN;
6309 dword s_cversion=CV_SUBSCREEN;
6310
6311 if(!p_mputl(section_id,f))
6312 {
6313 pack_fclose(f);
6314 return false;
6315 }
6316
6317 if(!p_iputw(s_version,f))
6318 {
6319 pack_fclose(f);
6320 return false;
6321 }
6322
6323 if(!p_iputw(s_cversion,f))
6324 {
6325 pack_fclose(f);
6326 return false;
6327 }
6328
6329 if(savefrom.write(f))
6330 {
6331 pack_fclose(f);
6332 return false;
6333 }
6334
6335 pack_fclose(f);
6336 return true;
6337 }
6338
6339 bool load_subscreen(const char *path, ZCSubscreen& loadto)
6340 {
6341 //open the file
6342 PACKFILE *f=pack_fopen_password(path,F_READ, "");
6343
6344 if(!f)
6345 return false;
6346
6347 dword section_id;
6348 dword s_version;
6349 dword s_cversion;
6350
6351 if(!p_mgetl(&section_id,f))
6352 {
6353 pack_fclose(f);
6354 return false;
6355 }
6356
6357 if(section_id!=ID_SUBSCREEN)
6358 {
6359 pack_fclose(f);
6360 return false;
6361 }
6362
6363 if(!p_igetw(&s_version,f))
6364 {
6365 pack_fclose(f);
6366 return false;
6367 }
6368
6369 if(!p_igetw(&s_cversion,f))
6370 {
6371 pack_fclose(f);
6372 return false;
6373 }
6374
6375 if(s_version < 8)
6376 {
6377 subscreen_group g;
6378 memset(&g,0,sizeof(subscreen_group));
6379 if(read_one_old_subscreen(f,&g,s_version)!=0)
6380 {
6381 pack_fclose(f);
6382 return false;
6383 }
6384 if(g.ss_type != loadto.sub_type)
6385 {
6386 pack_fclose(f);
6387 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6388 subscr_names[g.ss_type], subscr_names[loadto.sub_type]));
6389 return false;
6390 }
6391 loadto.clear();
6392 if(g.objects[0].type != ssoNULL)
6393 loadto.load_old(g);
6394 }
6395 else
6396 {
6397 ZCSubscreen tmp = ZCSubscreen();
6398 if (tmp.read(f, s_version))
6399 {
6400 pack_fclose(f);
6401 return false;
6402 }
6403 if(tmp.sub_type != loadto.sub_type)
6404 {
6405 pack_fclose(f);
6406 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6407 subscr_names[tmp.sub_type], subscr_names[loadto.sub_type]));
6408 return false;
6409 }
6410 loadto.clear();
6411 loadto = tmp;
6412 }
6413
6414 pack_fclose(f);
6415 return true;
6416 }
6417
6418 bool setMapCount2(int32_t c)
6419 {
6420 int32_t oldmapcount=map_count;
6421 int32_t currmap=Map.getCurrMap();
6422
6423 bound(c,1,MAXMAPS);
6424 map_count=c;
6425
6426 try
6427 {
6428 TheMaps.resize(c*MAPSCRS);
6429 Map.force_refr_pointer();
6430 map_autolayers.resize(c*6);
6431 }
6432 catch(...)
6433 {
6434 jwin_alert("Error","Failed to change map count.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
6435 return false;
6436 }
6437
6438 bound(currmap,0,c-1);
6439 if(map_count>oldmapcount)
6440 {
6441 for(int32_t mc=oldmapcount; mc<map_count; mc++)
6442 {
6443 Map.setCurrMap(mc);
6444
6445 for(int32_t ms=0; ms<MAPSCRS; ms++)
6446 {
6447 Map.clearscr(ms);
6448 }
6449 }
6450 Map.setCurrMap(currmap);
6451 }
6452 else
6453 {
6454 Map.setCurrMap(currmap);
6455 if(!layers_valid(Map.CurrScr()))
6456 fix_layers(Map.CurrScr(), false);
6457
6458 for(int32_t i=0; i<MAXDMAPS; i++)
6459 {
6460 if(DMaps[i].map>=map_count)
6461 {
6462 DMaps[i].map=map_count-1;
6463 }
6464 }
6465 }
6466
6467 return true;
6468 }
6469
6470 extern BITMAP *bmap;
6471
6472 static bool loading_file_new = false;
6473 1 int32_t init_quest()
6474 {
6475 char qstdat_string[2048];
6476 1 strcpy(qstdat_string, "modules/classic/default.qst");
6477
6478 char buf[2048];
6479
6480 1 loading_file_new = true;
6481 1 load_quest(qstdat_string);
6482 1 loading_file_new = false;
6483
6484 1 sprintf(buf,"ZC Editor - Untitled Quest");
6485 1 set_window_title(buf);
6486 1 zinit.last_map = 0;
6487 1 zinit.last_screen = 0;
6488
6489
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(bmap != NULL)
6490 {
6491 destroy_bitmap(bmap);
6492 bmap=NULL;
6493 }
6494
6495 1 return 0;
6496 }
6497
6498 void set_questpwd(std::string_view pwd, bool use_keyfile)
6499 {
6500 header.use_keyfile=use_keyfile;
6501
6502 // string_view actually has some quirks that make it less than ideal here.
6503 // It'd probably be best to replace it, but this works for now.
6504 memset(header.password, 0, 256);
6505 strcpy(header.password, pwd.data());
6506 header.dirty_password=true;
6507
6508 cvs_MD5Context ctx;
6509 cvs_MD5Init(&ctx);
6510 cvs_MD5Update(&ctx, (const uint8_t*)header.password, strlen(header.password));
6511 cvs_MD5Final(header.pwd_hash, &ctx);
6512 }
6513
6514
6515 bool is_null_pwd_hash(uint8_t *pwd_hash)
6516 {
6517 cvs_MD5Context ctx;
6518 uint8_t md5sum[16];
6519 char pwd[2]="";
6520
6521 cvs_MD5Init(&ctx);
6522 cvs_MD5Update(&ctx, (const uint8_t*)pwd, (unsigned)strlen(pwd));
6523 cvs_MD5Final(md5sum, &ctx);
6524
6525 return (memcmp(md5sum,pwd_hash,16)==0);
6526 }
6527
6528 static DIALOG pwd_dlg[] =
6529 {
6530 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
6531 { jwin_win_proc, 0, 0, 224+22+1, 88+10+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "Requires Authorization", NULL, NULL },
6532 { jwin_text_proc, 16, 28, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "File name:", NULL, NULL },
6533 // 2 (filename)
6534 { jwin_text_proc, 72, 28, 128, 8, vc(11), vc(1), 0, 0, 24, 0, NULL, NULL, NULL },
6535 { jwin_text_proc, 16, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, (void *) "Challenge:", NULL, NULL },
6536 // 4 (challenge hash)
6537 { jwin_text_proc, 72, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6538 { jwin_text_proc, 16, 42+10, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Password:", NULL, NULL },
6539 // 6 (password)
6540 { jwin_edit_proc, 72, 38+10, 120+39, 16, vc(12), vc(1), 0, 0, 255, 0, NULL, NULL, NULL },
6541 { jwin_button_proc, 42, 62+10, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6542 { jwin_button_proc, 122, 62+10, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6543 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6544 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6545 };
6546
6547 int32_t reverse_string(char* str)
6548 {
6549
6550 if(NULL==str)
6551 {
6552 return -1; //no string
6553 }
6554
6555 int32_t l=(int32_t)strlen(str)-1; //get the string length
6556
6557 if(1==l)
6558 {
6559 return 1;
6560 }
6561
6562 char c;
6563
6564 for(int32_t x=0; x < l; x++,l--)
6565 {
6566 c = str[x];
6567 str[x] = str[l];
6568 str[l] = c;
6569 }
6570
6571 return 0;
6572 }
6573
6574 #ifdef __GNUC__
6575 #pragma GCC diagnostic push
6576 #pragma GCC diagnostic ignored "-Wunreachable-code"
6577 #endif
6578
6579 9 int32_t quest_access(const char *filename, zquestheader *hdr)
6580 {
6581 #ifdef __EMSCRIPTEN__
6582 return 1;
6583 #endif
6584
6585 //Protection against compiling a release version with password protection off.
6586 static bool passguard = false;
6587
6588 #if ( !(defined _DEBUG) || (defined _RELEASE || defined NDEBUG || defined _NDEBUG) )
6589 #define MUST_HAVE_PASSWORD
6590 9 passguard = true;
6591 #endif
6592
6593 #if ( !(defined MUST_HAVE_PASSWORD) || defined _NPASS )
6594 #if (defined _MSC_VER || defined _NPASS)
6595 return 1;
6596 #endif
6597 #endif
6598
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(devpwd()) return 1;
6599
6600 char hash_string[33];
6601
6602 if((get_debug() && (!(CHECK_CTRL_CMD))) || is_null_pwd_hash(hdr->pwd_hash))
6603 {
6604 return 1;
6605 }
6606
6607 if(check_keyfiles(filename, {KEYFILE_MASTER,KEYFILE_ZPWD}, hdr))
6608 return true;
6609
6610 pwd_dlg[0].dp2=get_zc_font(font_lfont);
6611 pwd_dlg[2].dp=get_filename(filename);
6612 cvs_MD5Context ctx;
6613 uint8_t md5sum[16]={0};
6614 char response[33]="";
6615 char prompt[256]="";
6616
6617 memcpy(md5sum, hdr->pwd_hash, 16);
6618
6619 for(int32_t i=0; i<300; ++i)
6620 {
6621 for(int32_t j=0; j<16; ++j)
6622 {
6623 sprintf(response+j*2, "%02x", md5sum[j]);
6624 }
6625
6626 if(i&1)
6627 {
6628 reverse_string(response);
6629 }
6630
6631 if(i==149)
6632 {
6633 strcpy(hash_string, response);
6634 }
6635
6636 cvs_MD5Init(&ctx);
6637 cvs_MD5Update(&ctx, (const uint8_t*)response, (unsigned)strlen(response));
6638 cvs_MD5Final(md5sum, &ctx);
6639 }
6640
6641 pwd_dlg[4].dp=hash_string;
6642
6643 if(get_debug() && (CHECK_CTRL_CMD)) //...what is this doing?
6644 {
6645 sprintf(prompt,"%s",response);
6646 }
6647
6648 pwd_dlg[6].dp=prompt;
6649
6650 large_dialog(pwd_dlg);
6651
6652 int32_t cancel = do_zqdialog(pwd_dlg,6);
6653
6654 if(cancel == 8)
6655 return 2;
6656
6657 bool ret=check_questpwd(hdr, prompt);
6658
6659 if(!ret)
6660 {
6661 ret=(strcmp(response,prompt)==0);
6662 }
6663 return ret ? 1 : 0;
6664 9 }
6665
6666 void set_rules(byte* newrules);
6667 8 void popup_bugfix_dlg(const char* cfg)
6668 {
6669 8 bool dont_show_again = zc_get_config("zquest",cfg,0);
6670
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
8 if(!dont_show_again && hasCompatRulesEnabled())
6671 {
6672
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
24 AlertDialog("Apply New Bugfixes",
6673
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 "New bugfixes found that can be applied to this quest!"
6674 "\nWould you like to apply them?"
6675 "\n(Applies 'Bugfix' rule template, un-checking compat rules)",
6676 8 [&](bool ret,bool dsa)
6677 {
6678 if(ret)
6679 {
6680 applyRuleTemplate(ruletemplateFixCompat);
6681 }
6682 if(dsa)
6683 {
6684 zc_set_config("zquest",cfg,1);
6685 }
6686 },
6687
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
8 "Yes","No",
6688 0,false, //timeout - none
6689 true //"Don't show this again"
6690
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 ).show();
6691 8 }
6692 8 }
6693
6694 #ifdef __GNUC__
6695 #pragma GCC diagnostic pop
6696 #endif
6697
6698 // wrapper to reinitialize everything on an error
6699 9 int32_t load_quest(const char *filename, bool show_progress)
6700 {
6701 char buf[2048];
6702 // if(encrypted)
6703 // setPackfilePassword(datapwd);
6704 byte skip_flags[4];
6705
6706
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 9 times.
45 for(int32_t i=0; i<4; ++i)
6707 {
6708 36 skip_flags[i]=0;
6709 36 }
6710
2/2
✓ Branch 0 taken 6210 times.
✓ Branch 1 taken 9 times.
6219 for(int32_t i=0; i<qr_MAX; i++)
6711 6210 set_qr(i,0);
6712 9 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,show_progress,skip_flags);
6713 // setPackfilePassword(NULL);
6714
6715
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(ret!=qe_OK)
6716 {
6717 init_quest();
6718 }
6719 else
6720 {
6721 9 int32_t accessret = quest_access(filename, &header);
6722
6723
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(accessret != 1)
6724 {
6725 init_quest();
6726
6727 if(accessret == 0)
6728 ret=qe_pwd;
6729 else
6730 ret=qe_cancel;
6731 }
6732 else
6733 {
6734 9 Map.clear();
6735 9 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6736 9 Map.setCurrScr(zinit.last_screen);
6737 extern int32_t current_mappage;
6738 9 current_mappage = 0;
6739 9 bool found_default = false;
6740
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 65 times.
72 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6741 {
6742 65 auto &pg = map_page[q];
6743
4/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 54 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 9 times.
65 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6744 {
6745 2 current_mappage = q;
6746 2 break;
6747 }
6748
4/8
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 56 times.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 7 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
63 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6749 56 continue;
6750 else
6751 {
6752 7 current_mappage = q;
6753 7 found_default = true;
6754 }
6755 7 }
6756 9 refresh(rALL);
6757 9 refresh_pal();
6758 9 set_rules(quest_rules);
6759 9 saved = true;
6760
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
9 if(!(loading_file_new && zc_get_config("zquest","auto_filenew_bugfixes",1)))
6761 8 popup_bugfix_dlg("dsa_compatrule");
6762
6763
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(bmap != NULL)
6764 {
6765 destroy_bitmap(bmap);
6766 bmap=NULL;
6767 }
6768
6769
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
9 if (show_progress)
6770 {
6771 1 sprintf(buf,"ZC Editor - [%s]", get_filename(filename));
6772 1 set_window_title(buf);
6773 1 }
6774 }
6775 }
6776
6777 9 Map.ClearCommandHistory();
6778
6779 9 return ret;
6780 }
6781
6782 int32_t load_tileset(const char *filename, dword tsetflags)
6783 {
6784 char buf[2048];
6785 byte skip_flags[4];
6786
6787 for(int32_t i=0; i<4; ++i)
6788 skip_flags[i]=0;
6789 for(int32_t i=0; i<qr_MAX; i++)
6790 set_qr(i,0);
6791 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,true,skip_flags,1,true,0,tsetflags);
6792
6793 if(ret!=qe_OK)
6794 init_quest();
6795 else
6796 {
6797 int32_t accessret = quest_access(filename, &header);
6798
6799 if(accessret != 1)
6800 {
6801 init_quest();
6802
6803 if(accessret == 0)
6804 ret=qe_pwd;
6805 else
6806 ret=qe_cancel;
6807 }
6808 else
6809 {
6810 Map.clear();
6811 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6812 Map.setCurrScr(zinit.last_screen);
6813 extern int32_t current_mappage;
6814 current_mappage = 0;
6815 bool found_default = false;
6816 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6817 {
6818 auto &pg = map_page[q];
6819 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6820 {
6821 current_mappage = q;
6822 break;
6823 }
6824 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6825 continue;
6826 else
6827 {
6828 current_mappage = q;
6829 found_default = true;
6830 }
6831 }
6832 refresh(rALL);
6833 refresh_pal();
6834 set_rules(quest_rules);
6835 if(!zc_get_config("zquest","auto_filenew_bugfixes",1))
6836 popup_bugfix_dlg("dsa_compatrule");
6837
6838 if(bmap != NULL)
6839 {
6840 destroy_bitmap(bmap);
6841 bmap=NULL;
6842 }
6843
6844 set_window_title("ZC Editor - Untitled Quest");
6845 first_save = saved = false;
6846 memset(filepath,0,255);
6847 memset(temppath,0,255);
6848 }
6849 }
6850
6851 Map.ClearCommandHistory();
6852
6853 return ret;
6854 }
6855
6856 60 bool write_midi(MIDI *m,PACKFILE *f)
6857 {
6858 int32_t c;
6859
6860
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 60 times.
60 if(!p_mputw(m->divisions,f)) return false;
6861
6862
2/2
✓ Branch 0 taken 1920 times.
✓ Branch 1 taken 60 times.
1980 for(c=0; c<MIDI_TRACKS; c++)
6863 {
6864
1/2
✓ Branch 0 taken 1920 times.
✗ Branch 1 not taken.
1920 if(!p_mputl(m->track[c].len,f)) return false;
6865
6866
2/2
✓ Branch 0 taken 1428 times.
✓ Branch 1 taken 492 times.
1920 if(m->track[c].len > 0)
6867 {
6868
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!pfwrite(m->track[c].data,m->track[c].len,f))
6869 return false;
6870 492 }
6871 1920 }
6872
6873 60 return true;
6874 60 }
6875
6876 bool write_music(int32_t format, MIDI* m, PACKFILE *f)
6877 {
6878 // format - data format (midi, nsf, ...)
6879 // m - pointer to data.
6880
6881 int32_t c;
6882
6883 switch(format)
6884 {
6885 case MFORMAT_MIDI:
6886
6887 if(!p_mputw(m->divisions,f)) return false;
6888
6889 for(c=0; c<MIDI_TRACKS; c++)
6890 {
6891 if(!p_mputl(m->track[c].len,f)) return false;
6892
6893 if(m->track[c].len > 0)
6894 {
6895 if(!pfwrite(m->track[c].data,m->track[c].len,f))
6896 return false;
6897 }
6898 }
6899
6900 break;
6901
6902 case MFORMAT_NSF:
6903
6904 break;
6905
6906 default:
6907 return false;
6908 break;
6909 }
6910
6911 return true;
6912 }
6913
6914 6 int32_t writeheader(PACKFILE *f, zquestheader *Header)
6915 {
6916 6 dword section_id=ID_HEADER;
6917 6 dword section_version=V_HEADER;
6918 6 dword section_cversion=CV_HEADER;
6919 6 dword section_size=0;
6920
6921 //file header string
6922
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!pfwrite(Header->id_str,sizeof(Header->id_str),f))
6923 {
6924 new_return(1);
6925 }
6926
6927 //section id
6928
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
6929 {
6930 new_return(2);
6931 }
6932
6933 //section version info
6934
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
6935 {
6936 new_return(3);
6937 }
6938
6939
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
6940 {
6941 new_return(4);
6942 }
6943
6944
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
6945 {
6946 12 fake_pack_writing=(writecycle==0);
6947
6948 //section size
6949
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
6950 {
6951 new_return(5);
6952 }
6953
6954 12 writesize=0;
6955
6956 //finally... section data
6957
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(Header->zelda_version,f))
6958 {
6959 new_return(6);
6960 }
6961
6962
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->build,f))
6963 {
6964 new_return(7);
6965 }
6966
6967
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->pwd_hash,sizeof(Header->pwd_hash),f))
6968 {
6969 new_return(8);
6970 }
6971
6972
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(Header->internal,f))
6973 {
6974 new_return(10);
6975 }
6976
6977
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->quest_number,f))
6978 {
6979 new_return(11);
6980 }
6981
6982
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->version,16,f))
6983 {
6984 new_return(12);
6985 }
6986
6987
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->minver,16,f))
6988 {
6989 new_return(13);
6990 }
6991
6992
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->title,sizeof(Header->title),f))
6993 {
6994 new_return(14);
6995 }
6996
6997
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->author,sizeof(Header->author),f))
6998 {
6999 new_return(15);
7000 }
7001
7002
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->use_keyfile,f))
7003 {
7004 new_return(16);
7005 }
7006
7007
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->data_flags,sizeof(Header->data_flags),f))
7008 {
7009 new_return(17);
7010 }
7011
7012
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(Header->templatepath,sizeof(Header->templatepath),f))
7013 {
7014 new_return(19);
7015 }
7016
7017
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(0,f)) //why are we doing this?
7018 //this is for map count, it seems. -Z
7019 {
7020 new_return(20);
7021 }
7022
7023 12 auto version = getVersion();
7024
7025
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(version.major,f))
7026 {
7027 new_return(21);
7028 }
7029
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(version.minor,f))
7030 {
7031 new_return(22);
7032 }
7033
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(version.patch,f))
7034 {
7035 new_return(23);
7036 }
7037 // Fourth component is deprecated.
7038
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
7039 {
7040 new_return(24);
7041 }
7042
7043 // Numerous prerelease stages is deprecated.
7044
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
7045 {
7046 new_return(25);
7047 }
7048
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
7049 {
7050 new_return(26);
7051 }
7052
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
7053 {
7054 new_return(27);
7055 }
7056
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(0,f))
7057 {
7058 new_return(28);
7059 }
7060
7061
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(BUILDTM_YEAR,f))
7062 {
7063 new_return(29);
7064 }
7065
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(BUILDTM_MONTH,f))
7066 {
7067 new_return(30);
7068 }
7069
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(BUILDTM_DAY,f))
7070 {
7071 new_return(31);
7072 }
7073
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(BUILDTM_HOUR,f))
7074 {
7075 new_return(32);
7076 }
7077
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(BUILDTM_MINUTE,f))
7078 {
7079 new_return(33);
7080 }
7081
7082
7083
7084 char tempsig[256];
7085 12 memset(tempsig, 0, 256);
7086 12 strcpy(tempsig, DEV_SIGNOFF);
7087
7088
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempsig,256,f))
7089 {
7090 new_return(34);
7091 }
7092
7093 char tempcompilersig[256];
7094 12 memset(tempcompilersig, 0, 256);
7095 12 strcpy(tempcompilersig, COMPILER_NAME);
7096
7097
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempcompilersig,256,f))
7098 {
7099 new_return(35);
7100 }
7101
7102 char tempcompilerversion[256];
7103 12 memset(tempcompilerversion, 0, 256);
7104 #ifdef _MSC_VER
7105 zc_itoa(_MSC_VER,tempcompilerversion,10);
7106 #else
7107 12 strcpy(tempcompilerversion, COMPILER_VERSION);
7108 #endif
7109
7110
7111
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempcompilerversion,256,f))
7112 {
7113 new_return(36);
7114 }
7115
7116
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite("ZQuest Classic",1024,f))
7117 {
7118 new_return(37);
7119 }
7120
7121
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(V_ZC_COMPILERSIG,f))
7122 {
7123 new_return(38);
7124 }
7125 #ifdef _MSC_VER
7126 if(!p_iputl((_MSC_VER / 100),f))
7127 {
7128 new_return(39);
7129 }
7130 #else
7131
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(COMPILER_V_FIRST,f))
7132 {
7133 new_return(39);
7134 }
7135 #endif
7136
7137
7138
7139 #ifdef _MSC_VER
7140 if(!p_iputl((_MSC_VER % 100),f))
7141 {
7142 new_return(41);
7143 }
7144 #else
7145
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(COMPILER_V_SECOND,f))
7146 {
7147 new_return(41);
7148 }
7149 #endif
7150
7151 #ifdef _MSC_VER
7152 # if _MSC_VER >= 1400
7153 if(!p_iputl((_MSC_FULL_VER % 100000),f))
7154 {
7155 new_return(40);
7156 }
7157 # else
7158 if(!p_iputl((_MSC_FULL_VER % 10000),f))
7159 {
7160 new_return(40);
7161 }
7162 #endif
7163 #else
7164
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(COMPILER_V_THIRD,f))
7165 {
7166 new_return(40);
7167 }
7168 #endif
7169
7170 #ifdef _MSC_VER
7171 if(!p_iputl((_MSC_BUILD),f))
7172 {
7173 new_return(42);
7174 }
7175 #else
7176
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(COMPILER_V_FOURTH,f))
7177 {
7178 new_return(42);
7179 }
7180 #endif
7181
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(0,f)) //was V_ZC_DEVSIG, no longer used
7182 {
7183 new_return(43);
7184 }
7185
7186 char tempmodulename[1024];
7187 12 memset(tempmodulename, 0, 1024);
7188 12 strcpy(tempmodulename, moduledata.module_name);
7189
7190
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempmodulename,1024,f))
7191 {
7192 new_return(44);
7193 }
7194
7195 char tempdate[256];
7196 12 memset(tempdate, 0, 256);
7197 12 strcpy(tempdate, __DATE__);
7198
7199
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&tempdate,256,f))
7200 {
7201 new_return(45);
7202 }
7203 char temptime[256];
7204 12 memset(temptime, 0, 256);
7205 12 strcpy(temptime, __TIME__);
7206
7207
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&temptime,256,f))
7208 {
7209 new_return(46);
7210 }
7211
7212
7213 char temptimezone[6];
7214 12 memset(temptimezone, 0, 6);
7215 12 strcpy(temptimezone, __TIMEZONE__);
7216
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&temptimezone,6,f))
7217 {
7218 new_return(47);
7219 }
7220
7221
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->external_zinfo ? 1 : 0, f))
7222 {
7223 new_return(48);
7224 }
7225
7226
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(isStableRelease() ? 0 : 1, f))
7227 {
7228 new_return(49);
7229 }
7230
7231
3/6
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
12 if(!p_putcstr(version.version_string, f))
7232 {
7233 new_return(50);
7234 }
7235
7236
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7237 {
7238 6 section_size=writesize;
7239 6 }
7240 12 }
7241
7242
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7243 {
7244 char ebuf[80];
7245 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7246 jwin_alert("Error: writeheader()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7247 }
7248
7249 6 new_return(0);
7250 }
7251
7252 6 int32_t writerules(PACKFILE *f, zquestheader *Header)
7253 {
7254 //these are here to bypass compiler warnings about unused arguments
7255 6 Header=Header;
7256
7257 6 dword section_id=ID_RULES;
7258 6 dword section_version=V_RULES;
7259 6 dword section_cversion=CV_RULES;
7260 6 dword section_size=0;
7261
7262 //section id
7263
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7264 {
7265 new_return(1);
7266 }
7267
7268 //section version info
7269
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
7270 {
7271 new_return(2);
7272 }
7273
7274
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
7275 {
7276 new_return(3);
7277 }
7278
7279
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputl(V_COMPATRULE,f))
7280 {
7281 new_return(6);
7282 }
7283
7284
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7285 {
7286 12 fake_pack_writing=(writecycle==0);
7287
7288 //section size
7289
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
7290 {
7291 new_return(4);
7292 }
7293
7294 12 writesize=0;
7295
7296 //finally... section data
7297
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(quest_rules,QUESTRULES_NEW_SIZE,f))
7298 {
7299 new_return(5);
7300 }
7301
7302
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7303 {
7304 6 section_size=writesize;
7305 6 }
7306 12 }
7307
7308
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7309 {
7310 char ebuf[80];
7311 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7312 jwin_alert("Error: writerules()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7313 }
7314
7315 6 new_return(0);
7316 }
7317
7318
7319 6 int32_t writedoorcombosets(PACKFILE *f, zquestheader *Header)
7320 {
7321 //these are here to bypass compiler warnings about unused arguments
7322 6 Header=Header;
7323
7324 6 dword section_id=ID_DOORS;
7325 6 dword section_version=V_DOORS;
7326 6 dword section_cversion=CV_DOORS;
7327 6 dword section_size=0;
7328
7329 //section id
7330
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7331 {
7332 new_return(1);
7333 }
7334
7335 //section version info
7336
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
7337 {
7338 new_return(2);
7339 }
7340
7341
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
7342 {
7343 new_return(3);
7344 }
7345
7346
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7347 {
7348 12 fake_pack_writing=(writecycle==0);
7349
7350 //section size
7351
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
7352 {
7353 new_return(4);
7354 }
7355
7356 12 writesize=0;
7357
7358 //finally... section data
7359
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(door_combo_set_count,f))
7360 {
7361 new_return(5);
7362 }
7363
7364
2/2
✓ Branch 0 taken 164 times.
✓ Branch 1 taken 12 times.
176 for(int32_t i=0; i<door_combo_set_count; i++)
7365 {
7366 //name
7367
1/2
✓ Branch 0 taken 164 times.
✗ Branch 1 not taken.
164 if(!pfwrite(&DoorComboSets[i].name,sizeof(DoorComboSets[0].name),f))
7368 {
7369 new_return(6);
7370 }
7371
7372 //up door
7373
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7374 {
7375
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 5904 times.
7380 for(int32_t k=0; k<4; k++)
7376 {
7377
1/2
✓ Branch 0 taken 5904 times.
✗ Branch 1 not taken.
5904 if(!p_iputw(DoorComboSets[i].doorcombo_u[j][k],f))
7378 {
7379 new_return(7);
7380 }
7381 5904 }
7382 1476 }
7383
7384
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7385 {
7386
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 5904 times.
7380 for(int32_t k=0; k<4; k++)
7387 {
7388
1/2
✓ Branch 0 taken 5904 times.
✗ Branch 1 not taken.
5904 if(!p_putc(DoorComboSets[i].doorcset_u[j][k],f))
7389 {
7390 new_return(8);
7391 }
7392 5904 }
7393 1476 }
7394
7395 //down door
7396
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7397 {
7398
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 5904 times.
7380 for(int32_t k=0; k<4; k++)
7399 {
7400
1/2
✓ Branch 0 taken 5904 times.
✗ Branch 1 not taken.
5904 if(!p_iputw(DoorComboSets[i].doorcombo_d[j][k],f))
7401 {
7402 new_return(9);
7403 }
7404 5904 }
7405 1476 }
7406
7407
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7408 {
7409
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 5904 times.
7380 for(int32_t k=0; k<4; k++)
7410 {
7411
1/2
✓ Branch 0 taken 5904 times.
✗ Branch 1 not taken.
5904 if(!p_putc(DoorComboSets[i].doorcset_d[j][k],f))
7412 {
7413 new_return(10);
7414 }
7415 5904 }
7416 1476 }
7417
7418
7419 //left door
7420
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7421 {
7422
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 8856 times.
10332 for(int32_t k=0; k<6; k++)
7423 {
7424
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 if(!p_iputw(DoorComboSets[i].doorcombo_l[j][k],f))
7425
7426 {
7427 new_return(11);
7428 }
7429 8856 }
7430 1476 }
7431
7432
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7433 {
7434
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 8856 times.
10332 for(int32_t k=0; k<6; k++)
7435 {
7436
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 if(!p_putc(DoorComboSets[i].doorcset_l[j][k],f))
7437 {
7438 new_return(12);
7439 }
7440 8856 }
7441 1476 }
7442
7443 //right door
7444
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7445 {
7446
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 8856 times.
10332 for(int32_t k=0; k<6; k++)
7447 {
7448
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 if(!p_iputw(DoorComboSets[i].doorcombo_r[j][k],f))
7449 {
7450 new_return(13);
7451 }
7452 8856 }
7453 1476 }
7454
7455
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 164 times.
1640 for(int32_t j=0; j<9; j++)
7456 {
7457
2/2
✓ Branch 0 taken 1476 times.
✓ Branch 1 taken 8856 times.
10332 for(int32_t k=0; k<6; k++)
7458 {
7459
1/2
✓ Branch 0 taken 8856 times.
✗ Branch 1 not taken.
8856 if(!p_putc(DoorComboSets[i].doorcset_r[j][k],f))
7460 {
7461 new_return(14);
7462 }
7463 8856 }
7464 1476 }
7465
7466
7467 //up bomb rubble
7468
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7469 {
7470
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_iputw(DoorComboSets[i].bombdoorcombo_u[j],f))
7471 {
7472 new_return(15);
7473 }
7474 328 }
7475
7476
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7477 {
7478
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_putc(DoorComboSets[i].bombdoorcset_u[j],f))
7479 {
7480 new_return(16);
7481 }
7482 328 }
7483
7484 //down bomb rubble
7485
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7486 {
7487
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_iputw(DoorComboSets[i].bombdoorcombo_d[j],f))
7488 {
7489 new_return(17);
7490 }
7491 328 }
7492
7493
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7494 {
7495
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_putc(DoorComboSets[i].bombdoorcset_d[j],f))
7496 {
7497 new_return(18);
7498 }
7499 328 }
7500
7501 //left bomb rubble
7502
2/2
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 164 times.
656 for(int32_t j=0; j<3; j++)
7503 {
7504
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!p_iputw(DoorComboSets[i].bombdoorcombo_l[j],f))
7505 {
7506 new_return(19);
7507 }
7508 492 }
7509
7510
2/2
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 164 times.
656 for(int32_t j=0; j<3; j++)
7511 {
7512
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!p_putc(DoorComboSets[i].bombdoorcset_l[j],f))
7513 {
7514 new_return(20);
7515 }
7516 492 }
7517
7518 //right bomb rubble
7519
2/2
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 164 times.
656 for(int32_t j=0; j<3; j++)
7520 {
7521
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!p_iputw(DoorComboSets[i].bombdoorcombo_r[j],f))
7522 {
7523 new_return(21);
7524 }
7525 492 }
7526
7527
2/2
✓ Branch 0 taken 492 times.
✓ Branch 1 taken 164 times.
656 for(int32_t j=0; j<3; j++)
7528 {
7529
1/2
✓ Branch 0 taken 492 times.
✗ Branch 1 not taken.
492 if(!p_putc(DoorComboSets[i].bombdoorcset_r[j],f))
7530 {
7531 new_return(22);
7532 }
7533 492 }
7534
7535 //walkthrough stuff
7536
2/2
✓ Branch 0 taken 656 times.
✓ Branch 1 taken 164 times.
820 for(int32_t j=0; j<4; j++)
7537 {
7538
1/2
✓ Branch 0 taken 656 times.
✗ Branch 1 not taken.
656 if(!p_iputw(DoorComboSets[i].walkthroughcombo[j],f))
7539 {
7540 new_return(23);
7541 }
7542 656 }
7543
7544
2/2
✓ Branch 0 taken 656 times.
✓ Branch 1 taken 164 times.
820 for(int32_t j=0; j<4; j++)
7545 {
7546
1/2
✓ Branch 0 taken 656 times.
✗ Branch 1 not taken.
656 if(!p_putc(DoorComboSets[i].walkthroughcset[j],f))
7547 {
7548 new_return(24);
7549 }
7550 656 }
7551
7552 //flags
7553
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 164 times.
492 for(int32_t j=0; j<2; j++)
7554 {
7555
1/2
✓ Branch 0 taken 328 times.
✗ Branch 1 not taken.
328 if(!p_putc(DoorComboSets[i].flags[j],f))
7556 {
7557 new_return(25);
7558 }
7559 328 }
7560 164 }
7561
7562
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7563 {
7564 6 section_size=writesize;
7565 6 }
7566 12 }
7567
7568
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7569 {
7570 char ebuf[80];
7571 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7572 jwin_alert("Error: writedoorcombosets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7573 }
7574
7575 6 new_return(0);
7576 }
7577
7578 6 int32_t writedmaps(PACKFILE *f, word version, word build, word start_dmap, word max_dmaps)
7579 {
7580 //these are here to bypass compiler warnings about unused arguments
7581 6 version=version;
7582 6 build=build;
7583
7584 6 word dmap_count=count_dmaps();
7585 6 dword section_id=ID_DMAPS;
7586 6 dword section_version=V_DMAPS;
7587 6 dword section_cversion=CV_DMAPS;
7588 6 dword section_size=0;
7589
7590 //section id
7591
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7592 {
7593 new_return(1);
7594 }
7595
7596 //section version info
7597
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
7598 {
7599 new_return(2);
7600 }
7601
7602
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
7603 {
7604 new_return(3);
7605 }
7606
7607
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7608 {
7609 12 fake_pack_writing=(writecycle==0);
7610
7611 //section size
7612
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
7613 {
7614 new_return(4);
7615 }
7616
7617 12 writesize=0;
7618
7619
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 dmap_count=zc_min(dmap_count, max_dmaps);
7620
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 dmap_count=zc_min(dmap_count, MAXDMAPS-start_dmap);
7621
7622 //finally... section data
7623
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(dmap_count,f))
7624 {
7625 new_return(5);
7626 }
7627
7628
7629
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=start_dmap; i<start_dmap+dmap_count; i++)
7630 {
7631 6144 DMaps[i].validate_subscreens();
7632
7633
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].map,f))
7634 {
7635 new_return(6);
7636 }
7637
7638
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].level,f))
7639 {
7640 new_return(7);
7641 }
7642
7643
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].xoff,f))
7644 {
7645 new_return(8);
7646 }
7647
7648
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].compass,f))
7649 {
7650 new_return(9);
7651 }
7652
7653
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].color,f))
7654 {
7655 new_return(10);
7656 }
7657
7658
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].midi,f))
7659 {
7660 new_return(11);
7661 }
7662
7663
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].cont,f))
7664 {
7665 new_return(12);
7666 }
7667
7668
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].type,f))
7669 {
7670 new_return(13);
7671 }
7672
7673
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t j=0; j<8; j++)
7674 {
7675
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_putc(DMaps[i].grid[j],f))
7676 {
7677 new_return(14);
7678 }
7679 49152 }
7680
7681
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite(&DMaps[i].name,sizeof(DMaps[0].name)-1,f))
7682 {
7683 new_return(15);
7684 }
7685
7686
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putwstr(DMaps[i].title,f))
7687 {
7688 new_return(16);
7689 }
7690
7691
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite(&DMaps[i].intro,sizeof(DMaps[0].intro)-1,f))
7692 {
7693 new_return(17);
7694 }
7695
7696
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].minimap_1_tile,f))
7697 {
7698 new_return(18);
7699 }
7700
7701
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].minimap_1_cset,f))
7702 {
7703 new_return(19);
7704 }
7705
7706
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].minimap_2_tile,f))
7707 {
7708 new_return(20);
7709 }
7710
7711
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].minimap_2_cset,f))
7712 {
7713 new_return(21);
7714 }
7715
7716
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].largemap_1_tile,f))
7717 {
7718 new_return(22);
7719 }
7720
7721
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].largemap_1_cset,f))
7722 {
7723 new_return(23);
7724 }
7725
7726
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].largemap_2_tile,f))
7727 {
7728 new_return(24);
7729 }
7730
7731
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].largemap_2_cset,f))
7732 {
7733 new_return(25);
7734 }
7735
7736
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite(&DMaps[i].tmusic,sizeof(DMaps[0].tmusic)-1,f))
7737 {
7738 new_return(26);
7739 }
7740
7741
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].tmusictrack,f))
7742 {
7743 new_return(25);
7744 }
7745
7746
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].active_subscreen,f))
7747 {
7748 new_return(26);
7749 }
7750
7751
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].passive_subscreen,f))
7752 {
7753 new_return(27);
7754 }
7755
7756 byte disabled[32];
7757 6144 memset(disabled,0,32);
7758
7759
2/2
✓ Branch 0 taken 1572864 times.
✓ Branch 1 taken 6144 times.
1579008 for(int32_t j=0; j<MAXITEMS; j++)
7760 {
7761
1/2
✓ Branch 0 taken 1572864 times.
✗ Branch 1 not taken.
1572864 if(DMaps[i].disableditems[j])
7762 {
7763 disabled[j/8] |= (1 << (j%8));
7764 }
7765 1572864 }
7766
7767
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite(disabled,32,f))
7768 {
7769 new_return(28);
7770 }
7771
7772
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(DMaps[i].flags,f))
7773 {
7774 new_return(29);
7775 }
7776
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].sideview,f))
7777 {
7778 new_return(30);
7779 }
7780
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].script,f))
7781 {
7782 new_return(31);
7783 }
7784
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
7785 {
7786
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(DMaps[i].initD[q],f))
7787 {
7788 new_return(32);
7789 }
7790
7791 49152 }
7792
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
7793 {
7794
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 3194880 times.
3244032 for ( int32_t w = 0; w < 65; w++ )
7795 {
7796
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if (!p_putc(DMaps[i].initD_label[q][w],f))
7797 {
7798 new_return(33);
7799 }
7800 3194880 }
7801 49152 }
7802
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].active_sub_script,f))
7803 {
7804 new_return(34);
7805 }
7806
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].passive_sub_script,f))
7807 {
7808 new_return(35);
7809 }
7810
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t q = 0; q < 8; ++q)
7811 {
7812
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(DMaps[i].sub_initD[q],f))
7813 {
7814 new_return(36);
7815 }
7816 49152 }
7817
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t q = 0; q < 8; ++q)
7818 {
7819
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 3194880 times.
3244032 for(int32_t w = 0; w < 65; ++w)
7820 {
7821
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if(!p_putc(DMaps[i].sub_initD_label[q][w],f))
7822 {
7823 new_return(37);
7824 }
7825 3194880 }
7826 49152 }
7827
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].onmap_script,f))
7828 {
7829 new_return(38);
7830 }
7831
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t q = 0; q < 8; ++q)
7832 {
7833
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(DMaps[i].onmap_initD[q],f))
7834 {
7835 new_return(39);
7836 }
7837 49152 }
7838
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t q = 0; q < 8; ++q)
7839 {
7840
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 3194880 times.
3244032 for(int32_t w = 0; w < 65; ++w)
7841 {
7842
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if(!p_putc(DMaps[i].onmap_initD_label[q][w],f))
7843 {
7844 new_return(40);
7845 }
7846 3194880 }
7847 49152 }
7848
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(DMaps[i].mirrorDMap,f))
7849 {
7850 new_return(41);
7851 }
7852
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].tmusic_loop_start, f))
7853 {
7854 new_return(42);
7855 }
7856
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].tmusic_loop_end, f))
7857 {
7858 new_return(43);
7859 }
7860
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].tmusic_xfade_in, f))
7861 {
7862 new_return(44);
7863 }
7864
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].tmusic_xfade_out, f))
7865 {
7866 new_return(45);
7867 }
7868
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(DMaps[i].overlay_subscreen, f))
7869 new_return(46);
7870
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if (!p_iputl(DMaps[i].intro_string_id, f))
7871 new_return(47);
7872
7873 // Reserved for z3.
7874
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for(int32_t j=0; j<8; j++)
7875 {
7876
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 393216 times.
442368 for(int32_t k=0; k<8; k++)
7877 {
7878
1/2
✓ Branch 0 taken 393216 times.
✗ Branch 1 not taken.
393216 if(!p_putc(0,f))
7879 {
7880 new_return(48);
7881 }
7882 393216 }
7883 49152 }
7884 6144 }
7885
7886
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
7887 {
7888 6 section_size=writesize;
7889 6 }
7890 12 }
7891
7892
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
7893 {
7894 char ebuf[80];
7895 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7896 jwin_alert("Error: writedmaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7897 }
7898
7899 6 new_return(0);
7900 }
7901
7902 6 int32_t writemisccolors(PACKFILE *f, zquestheader *Header)
7903 {
7904 //these are here to bypass compiler warnings about unused arguments
7905 6 Header=Header;
7906
7907 6 dword section_id=ID_COLORS;
7908 6 dword section_version=V_COLORS;
7909 6 dword section_cversion=CV_COLORS;
7910 6 dword section_size = 0;
7911
7912 //section id
7913
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
7914 {
7915 new_return(1);
7916 }
7917
7918
7919 //section version info
7920
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
7921 {
7922 new_return(2);
7923 }
7924
7925
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
7926 {
7927 new_return(3);
7928 }
7929
7930
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7931 {
7932 12 fake_pack_writing=(writecycle==0);
7933
7934 //section size
7935
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
7936 {
7937 new_return(4);
7938 }
7939
7940 12 writesize=0;
7941
7942
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.text,f))
7943 {
7944 new_return(5);
7945 }
7946
7947
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.caption,f))
7948 {
7949 new_return(6);
7950 }
7951
7952
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.overw_bg,f))
7953 {
7954 new_return(7);
7955 }
7956
7957
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.dngn_bg,f))
7958 {
7959 new_return(8);
7960 }
7961
7962
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.dngn_fg,f))
7963 {
7964 new_return(9);
7965 }
7966
7967
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.cave_fg,f))
7968 {
7969 new_return(10);
7970 }
7971
7972
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.bs_dk,f))
7973 {
7974 new_return(11);
7975 }
7976
7977
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.bs_goal,f))
7978 {
7979 new_return(12);
7980 }
7981
7982
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.compass_lt,f))
7983 {
7984 new_return(13);
7985 }
7986
7987
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.compass_dk,f))
7988 {
7989 new_return(14);
7990 }
7991
7992
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.subscr_bg,f))
7993 {
7994 new_return(15);
7995 }
7996
7997
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.triframe_color,f))
7998 {
7999 new_return(16);
8000 }
8001
8002
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.hero_dot,f))
8003 {
8004 new_return(17);
8005 }
8006
8007
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.bmap_bg,f))
8008 {
8009 new_return(18);
8010 }
8011
8012
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.bmap_fg,f))
8013 {
8014 new_return(19);
8015 }
8016
8017
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.triforce_cset,f))
8018 {
8019 new_return(20);
8020 }
8021
8022
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.triframe_cset,f))
8023 {
8024 new_return(21);
8025 }
8026
8027
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.overworld_map_cset,f))
8028 {
8029 new_return(22);
8030 }
8031
8032
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.dungeon_map_cset,f))
8033 {
8034 new_return(23);
8035 }
8036
8037
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.blueframe_cset,f))
8038 {
8039 new_return(24);
8040 }
8041
8042
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.HCpieces_cset,f))
8043 {
8044 new_return(31);
8045 }
8046
8047
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.subscr_shadow,f))
8048 {
8049 new_return(32);
8050 }
8051
8052
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(QMisc.colors.msgtext,f))
8053 {
8054 new_return(33);
8055 }
8056
8057
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.triforce_tile,f))
8058 {
8059 new_return(34);
8060 }
8061
8062
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.triframe_tile,f))
8063 {
8064 new_return(35);
8065 }
8066
8067
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.overworld_map_tile,f))
8068 {
8069 new_return(36);
8070 }
8071
8072
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.dungeon_map_tile,f))
8073 {
8074 new_return(37);
8075 }
8076
8077
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.blueframe_tile,f))
8078 {
8079 new_return(38);
8080 }
8081
8082
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.colors.HCpieces_tile,f))
8083 {
8084 new_return(39);
8085 }
8086
8087
8088
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
8089 {
8090 6 section_size=writesize;
8091 6 }
8092 12 }
8093
8094
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
8095 {
8096 char ebuf[80];
8097 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8098 jwin_alert("Error: writemisccolors()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8099 }
8100
8101 6 new_return(0);
8102 }
8103
8104 6 int32_t writegameicons(PACKFILE *f, zquestheader *Header)
8105 {
8106 //these are here to bypass compiler warnings about unused arguments
8107 6 Header=Header;
8108
8109 6 dword section_id=ID_ICONS;
8110 6 dword section_version=V_ICONS;
8111 6 dword section_cversion=CV_ICONS;
8112 6 dword section_size = 0;
8113
8114 //section id
8115
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
8116 {
8117 new_return(1);
8118 }
8119
8120 //section version info
8121
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
8122 {
8123 new_return(2);
8124 }
8125
8126
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
8127 {
8128 new_return(3);
8129 }
8130
8131
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8132 {
8133 12 fake_pack_writing=(writecycle==0);
8134
8135 //section size
8136
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
8137 {
8138 new_return(4);
8139 }
8140
8141 12 writesize=0;
8142
8143
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
8144 {
8145
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(QMisc.icons[i],f))
8146 {
8147 new_return(5);
8148 }
8149 48 }
8150
8151
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
8152 {
8153 6 section_size=writesize;
8154 6 }
8155 12 }
8156
8157
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
8158 {
8159 char ebuf[80];
8160 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8161 jwin_alert("Error: writegameicons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8162 }
8163
8164 6 new_return(0);
8165 }
8166
8167 6 int32_t writemisc(PACKFILE *f, zquestheader *Header)
8168 {
8169 //these are here to bypass compiler warnings about unused arguments
8170 6 Header=Header;
8171
8172 6 dword section_id=ID_MISC;
8173 6 dword section_version=V_MISC;
8174 6 dword section_cversion=CV_MISC;
8175 6 word shops=count_shops(&QMisc);
8176 6 word infos=count_infos(&QMisc);
8177 6 word warprings=count_warprings(&QMisc);
8178 6 word triforces=8;
8179 6 dword section_size = 0;
8180
8181 //section id
8182
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
8183 {
8184 new_return(1);
8185 }
8186
8187
8188 //section version info
8189
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
8190 {
8191 new_return(2);
8192 }
8193
8194
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
8195 {
8196 new_return(3);
8197 }
8198
8199
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8200 {
8201 12 fake_pack_writing=(writecycle==0);
8202
8203 //section size
8204
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
8205 {
8206 new_return(4);
8207 }
8208
8209 12 writesize=0;
8210
8211 //shops
8212
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(shops,f))
8213 {
8214 new_return(5);
8215 }
8216
8217
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 12 times.
140 for(int32_t i=0; i<shops; i++)
8218 {
8219
1/2
✓ Branch 0 taken 128 times.
✗ Branch 1 not taken.
128 if(!pfwrite(QMisc.shop[i].name,sizeof(QMisc.shop[i].name)-1,f))
8220 {
8221 new_return(6);
8222 }
8223
8224
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8225 {
8226
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_putc(QMisc.shop[i].item[j],f))
8227 {
8228 new_return(7);
8229 }
8230 384 }
8231
8232
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8233 {
8234
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputw(QMisc.shop[i].price[j],f))
8235 {
8236 new_return(8);
8237 }
8238 384 }
8239
8240
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8241 {
8242
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_putc(QMisc.shop[i].hasitem[j],f))
8243 {
8244 new_return(9);
8245 }
8246 384 }
8247 128 }
8248
8249 //infos
8250
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(infos,f))
8251 {
8252 new_return(10);
8253 }
8254
8255
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 12 times.
140 for(int32_t i=0; i<infos; i++)
8256 {
8257
1/2
✓ Branch 0 taken 128 times.
✗ Branch 1 not taken.
128 if(!pfwrite(QMisc.info[i].name,sizeof(QMisc.info[i].name)-1,f))
8258 {
8259 new_return(11);
8260 }
8261
8262
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8263 {
8264
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputw(QMisc.info[i].str[j],f))
8265 {
8266 new_return(12);
8267 }
8268 384 }
8269
8270
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8271 {
8272
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputw(QMisc.info[i].price[j],f))
8273 {
8274 new_return(13);
8275 }
8276 384 }
8277 128 }
8278
8279 //warp rings
8280
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(warprings,f))
8281 {
8282 new_return(14);
8283 }
8284
8285
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 12 times.
156 for(int32_t i=0; i<warprings; i++)
8286 {
8287
2/2
✓ Branch 0 taken 1296 times.
✓ Branch 1 taken 144 times.
1440 for(int32_t j=0; j<9; j++)
8288 {
8289
1/2
✓ Branch 0 taken 1296 times.
✗ Branch 1 not taken.
1296 if(!p_iputw(QMisc.warp[i].dmap[j],f))
8290 {
8291 new_return(15);
8292 }
8293 1296 }
8294
8295
2/2
✓ Branch 0 taken 1296 times.
✓ Branch 1 taken 144 times.
1440 for(int32_t j=0; j<9; j++)
8296 {
8297
1/2
✓ Branch 0 taken 1296 times.
✗ Branch 1 not taken.
1296 if(!p_putc(QMisc.warp[i].scr[j],f))
8298 {
8299 new_return(16);
8300 }
8301 1296 }
8302
8303
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(!p_putc(QMisc.warp[i].size,f))
8304 {
8305 new_return(17);
8306 }
8307 144 }
8308
8309 //triforce pieces
8310
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(int32_t i=0; i<triforces; i++)
8311 {
8312
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(!p_putc(QMisc.triforce[i],f))
8313 {
8314 new_return(18);
8315 }
8316 96 }
8317
8318 //end string
8319
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(QMisc.endstring,f))
8320 {
8321 new_return(19);
8322 }
8323
8324 //V_MISC >= 8
8325
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 12 times.
140 for(int32_t i=0; i<shops; i++)
8326 {
8327
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 128 times.
512 for(int32_t j=0; j<3; j++)
8328 {
8329
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputw(QMisc.shop[i].str[j],f))
8330 {
8331 new_return(20);
8332 }
8333 384 }
8334 128 }
8335 //V_MISC >= 9
8336
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 12 times.
396 for ( int32_t q = 0; q < 32; q++ )
8337 {
8338
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_iputl(QMisc.questmisc[q],f))
8339 new_return(21);
8340 384 }
8341
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 12 times.
396 for ( int32_t q = 0; q < 32; q++ )
8342 {
8343
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 384 times.
49536 for ( int32_t j = 0; j < 128; j++ )
8344
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_putc(QMisc.questmisc_strings[q][j],f))
8345 new_return(22);
8346 384 }
8347 //V_MISC >= 11
8348
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(QMisc.zscript_last_compiled_version,f))
8349 new_return(23);
8350
8351 //V_MISC >= 12
8352
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t q = 0; q < sprMAX; ++q)
8353 {
8354
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(QMisc.sprites[q],f))
8355 new_return(24);
8356 3072 }
8357
8358 //V_MISC >= 13
8359
2/2
✓ Branch 0 taken 768 times.
✓ Branch 1 taken 12 times.
780 for(size_t q = 0; q < 64; ++q)
8360 {
8361 768 bottletype* bt = &(QMisc.bottle_types[q]);
8362
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if (!pfwrite(bt->name, 32, f))
8363 new_return(25);
8364
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 768 times.
3072 for(size_t j = 0; j < 3; ++j)
8365 {
8366
1/2
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
2304 if (!p_putc(bt->counter[j], f))
8367 new_return(25);
8368
1/2
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
2304 if (!p_iputw(bt->amount[j], f))
8369 new_return(25);
8370 2304 }
8371
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if (!p_putc(bt->flags, f))
8372 new_return(25);
8373
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if (!p_putc(bt->next_type, f))
8374 new_return(25);
8375 768 }
8376
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(size_t q = 0; q < 256; ++q)
8377 {
8378 3072 bottleshoptype* bst = &(QMisc.bottle_shop_types[q]);
8379
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if (!pfwrite(bst->name, 32, f))
8380 new_return(26);
8381
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 3072 times.
12288 for(size_t j = 0; j < 3; ++j)
8382 {
8383
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_putc(bst->fill[j], f))
8384 new_return(26);
8385
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputw(bst->comb[j], f))
8386 new_return(26);
8387
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_putc(bst->cset[j], f))
8388 new_return(26);
8389
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputw(bst->price[j], f))
8390 new_return(26);
8391
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9216 times.
9216 if (!p_iputw(bst->str[j], f))
8392 new_return(26);
8393 9216 }
8394 3072 }
8395
8396 //V_MISC >= 14
8397
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t q = 0; q < sfxMAX; ++q)
8398 {
8399
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(QMisc.miscsfx[q],f))
8400 new_return(27);
8401 3072 }
8402
8403
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
8404 {
8405 6 section_size=writesize;
8406 6 }
8407 12 }
8408
8409
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
8410 {
8411 char ebuf[80];
8412 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8413 jwin_alert("Error: writemisc()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8414 }
8415
8416 6 new_return(0);
8417 }
8418
8419 6 int32_t writeitems(PACKFILE *f, zquestheader *Header)
8420 {
8421 //these are here to bypass compiler warnings about unused arguments
8422 6 Header=Header;
8423
8424 6 dword section_id=ID_ITEMS;
8425 6 dword section_version=V_ITEMS;
8426 6 dword section_cversion=CV_ITEMS;
8427 // dword section_size=0;
8428 6 dword section_size = 0;
8429
8430 //section id
8431
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
8432 {
8433 new_return(1);
8434 }
8435
8436 //section version info
8437
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
8438 {
8439 new_return(2);
8440 }
8441
8442
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
8443 {
8444 new_return(3);
8445 }
8446
8447
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8448 {
8449 12 fake_pack_writing=(writecycle==0);
8450
8451 //section size
8452
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
8453 {
8454 new_return(4);
8455 }
8456
8457 12 writesize=0;
8458
8459 //finally... section data
8460
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(MAXITEMS,f))
8461 {
8462 new_return(5);
8463 }
8464
8465
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXITEMS; i++)
8466 {
8467
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!pfwrite(item_string[i], 64, f))
8468 {
8469 new_return(5);
8470 }
8471 3072 }
8472
8473
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXITEMS; i++)
8474 {
8475
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].tile,f))
8476 {
8477 new_return(6);
8478 }
8479
8480
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].misc_flags,f))
8481 {
8482 new_return(7);
8483 }
8484
8485
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].csets,f))
8486 {
8487 new_return(8);
8488 }
8489
8490
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].frames,f))
8491 {
8492 new_return(9);
8493 }
8494
8495
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].speed,f))
8496 {
8497 new_return(10);
8498 }
8499
8500
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].delay,f))
8501 {
8502 new_return(11);
8503 }
8504
8505
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].ltm,f))
8506 {
8507 new_return(12);
8508 }
8509
8510
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].family,f))
8511 {
8512 new_return(13);
8513 }
8514
8515
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].fam_type,f))
8516 {
8517 new_return(14);
8518 }
8519
8520
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].power,f))
8521 {
8522 new_return(14);
8523 }
8524
8525
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].flags,f))
8526 {
8527 new_return(15);
8528 }
8529
8530
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].script,f))
8531 {
8532 new_return(16);
8533 }
8534
8535
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].count,f))
8536 {
8537 new_return(17);
8538 }
8539
8540
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].amount,f))
8541 {
8542 new_return(18);
8543 }
8544
8545
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].collect_script,f))
8546 {
8547 new_return(19);
8548 }
8549
8550
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].setmax,f))
8551 {
8552 new_return(21);
8553 }
8554
8555
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].max,f))
8556 {
8557 new_return(22);
8558 }
8559
8560
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].playsound,f))
8561 {
8562 new_return(23);
8563 }
8564
8565
2/2
✓ Branch 0 taken 24576 times.
✓ Branch 1 taken 3072 times.
27648 for(int32_t j=0; j<8; j++)
8566 {
8567
1/2
✓ Branch 0 taken 24576 times.
✗ Branch 1 not taken.
24576 if(!p_iputl(itemsbuf[i].initiald[j],f))
8568 {
8569 new_return(24);
8570 }
8571 24576 }
8572
8573
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for(int32_t j=0; j<2; j++)
8574 {
8575
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(itemsbuf[i].initiala[j],f))
8576 {
8577 new_return(25);
8578 }
8579 6144 }
8580
8581
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn,f))
8582 {
8583 new_return(26);
8584 }
8585
8586
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn2,f))
8587 {
8588 new_return(27);
8589 }
8590
8591
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn3,f))
8592 {
8593 new_return(28);
8594 }
8595
8596
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn4,f))
8597 {
8598 new_return(29);
8599 }
8600
8601
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn5,f))
8602 {
8603 new_return(30);
8604 }
8605
8606
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn6,f))
8607 {
8608 new_return(31);
8609 }
8610
8611
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn7,f))
8612 {
8613 new_return(32);
8614 }
8615
8616
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn8,f))
8617 {
8618 new_return(33);
8619 }
8620
8621
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn9,f))
8622 {
8623 new_return(34);
8624 }
8625
8626
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].wpn10,f))
8627 {
8628 new_return(35);
8629 }
8630
8631
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].pickup_hearts,f))
8632 {
8633 new_return(36);
8634 }
8635
8636
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc1,f))
8637 {
8638 new_return(37);
8639 }
8640
8641
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc2,f))
8642 {
8643 new_return(38);
8644 }
8645
8646
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for(auto q = 0; q < 2; ++q)
8647 {
8648
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(itemsbuf[i].cost_amount[q],f))
8649 {
8650 new_return(39);
8651 }
8652 6144 }
8653
8654
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc3,f))
8655 {
8656 new_return(40);
8657 }
8658
8659
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc4,f))
8660 {
8661 new_return(41);
8662 }
8663
8664
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc5,f))
8665 {
8666 new_return(42);
8667 }
8668
8669
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc6,f))
8670 {
8671 new_return(43);
8672 }
8673
8674
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc7,f))
8675 {
8676 new_return(44);
8677 }
8678
8679
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc8,f))
8680 {
8681 new_return(45);
8682 }
8683
8684
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc9,f))
8685 {
8686 new_return(46);
8687 }
8688
8689
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].misc10,f))
8690 {
8691 new_return(47);
8692 }
8693
8694
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].usesound,f))
8695 {
8696 new_return(48);
8697 }
8698
8699
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].usesound2,f))
8700 {
8701 new_return(48);
8702 }
8703
8704 //New itemdata vars -Z
8705 //! version 27
8706
8707
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].useweapon,f))
8708 {
8709 new_return(49);
8710 }
8711
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].usedefence,f))
8712 {
8713 new_return(50);
8714 }
8715
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weaprange,f))
8716 {
8717 new_return(51);
8718 }
8719
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weapduration,f))
8720 {
8721 new_return(52);
8722 }
8723
2/2
✓ Branch 0 taken 30720 times.
✓ Branch 1 taken 3072 times.
33792 for ( int32_t q = 0; q < ITEM_MOVEMENT_PATTERNS; q++ ) {
8724
1/2
✓ Branch 0 taken 30720 times.
✗ Branch 1 not taken.
30720 if(!p_iputl(itemsbuf[i].weap_pattern[q],f))
8725 {
8726 new_return(53);
8727 }
8728 30720 }
8729 //version 28
8730
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].duplicates,f))
8731 {
8732 new_return(54);
8733 }
8734
2/2
✓ Branch 0 taken 24576 times.
✓ Branch 1 taken 3072 times.
27648 for ( int32_t q = 0; q < INITIAL_D; q++ )
8735 {
8736
1/2
✓ Branch 0 taken 24576 times.
✗ Branch 1 not taken.
24576 if(!p_iputl(itemsbuf[i].weap_initiald[q],f))
8737 {
8738 new_return(55);
8739 }
8740 24576 }
8741
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for ( int32_t q = 0; q < INITIAL_A; q++ )
8742 {
8743
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(itemsbuf[i].weap_initiala[q],f))
8744 {
8745 new_return(56);
8746 }
8747 6144 }
8748
8749
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].drawlayer,f))
8750 {
8751 new_return(57);
8752 }
8753
8754
8755
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hxofs,f))
8756 {
8757 new_return(58);
8758 }
8759
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hyofs,f))
8760 {
8761 new_return(59);
8762 }
8763
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hxsz,f))
8764 {
8765 new_return(60);
8766 }
8767
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hysz,f))
8768 {
8769 new_return(61);
8770 }
8771
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].hzsz,f))
8772 {
8773 new_return(62);
8774 }
8775
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].xofs,f))
8776 {
8777 new_return(63);
8778 }
8779
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].yofs,f))
8780 {
8781 new_return(64);
8782 }
8783
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hxofs,f))
8784 {
8785 new_return(65);
8786 }
8787
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hyofs,f))
8788 {
8789 new_return(66);
8790 }
8791
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hxsz,f))
8792 {
8793 new_return(67);
8794 }
8795
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hysz,f))
8796 {
8797 new_return(68);
8798 }
8799
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_hzsz,f))
8800 {
8801 new_return(69);
8802 }
8803
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_xofs,f))
8804 {
8805 new_return(70);
8806 }
8807
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_yofs,f))
8808 {
8809 new_return(71);
8810 }
8811
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].weaponscript,f))
8812 {
8813 new_return(72);
8814 }
8815
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].wpnsprite,f))
8816 {
8817 new_return(73);
8818 }
8819
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for(auto q = 0; q < 2; ++q)
8820 {
8821
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(itemsbuf[i].magiccosttimer[q],f))
8822 {
8823 new_return(74);
8824 }
8825 6144 }
8826
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].overrideFLAGS,f))
8827 {
8828 new_return(75);
8829 }
8830
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].tilew,f))
8831 {
8832 new_return(76);
8833 }
8834
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].tileh,f))
8835 {
8836 new_return(77);
8837 }
8838
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weapoverrideFLAGS,f))
8839 {
8840 new_return(78);
8841 }
8842
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_tilew,f))
8843 {
8844 new_return(79);
8845 }
8846
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].weap_tileh,f))
8847 {
8848 new_return(80);
8849 }
8850
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(itemsbuf[i].pickup,f))
8851 {
8852 new_return(81);
8853 }
8854
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].pstring,f))
8855 {
8856 new_return(82);
8857 }
8858
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].pickup_string_flags,f))
8859 {
8860 new_return(83);
8861 }
8862
8863
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for(auto q = 0; q < 2; ++q)
8864 {
8865
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(itemsbuf[i].cost_counter[q],f))
8866 {
8867 new_return(84);
8868 }
8869 6144 }
8870
8871 //InitD[] labels
8872
2/2
✓ Branch 0 taken 24576 times.
✓ Branch 1 taken 3072 times.
27648 for ( int32_t q = 0; q < 8; q++ )
8873 {
8874
2/2
✓ Branch 0 taken 1597440 times.
✓ Branch 1 taken 24576 times.
1622016 for ( int32_t w = 0; w < 65; w++ )
8875 {
8876
1/2
✓ Branch 0 taken 1597440 times.
✗ Branch 1 not taken.
1597440 if(!p_putc(itemsbuf[i].initD_label[q][w],f))
8877 {
8878 new_return(85);
8879 }
8880 1597440 }
8881
2/2
✓ Branch 0 taken 1597440 times.
✓ Branch 1 taken 24576 times.
1622016 for ( int32_t w = 0; w < 65; w++ )
8882 {
8883
1/2
✓ Branch 0 taken 1597440 times.
✗ Branch 1 not taken.
1597440 if(!p_putc(itemsbuf[i].weapon_initD_label[q][w],f))
8884 {
8885 new_return(86);
8886 }
8887 1597440 }
8888
2/2
✓ Branch 0 taken 1597440 times.
✓ Branch 1 taken 24576 times.
1622016 for ( int32_t w = 0; w < 65; w++ )
8889 {
8890
1/2
✓ Branch 0 taken 1597440 times.
✗ Branch 1 not taken.
1597440 if(!p_putc(itemsbuf[i].sprite_initD_label[q][w],f))
8891 {
8892 new_return(87);
8893 }
8894 1597440 }
8895
1/2
✓ Branch 0 taken 24576 times.
✗ Branch 1 not taken.
24576 if(!p_iputl(itemsbuf[i].sprite_initiald[q],f))
8896 {
8897 new_return(88);
8898 }
8899 24576 }
8900
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 3072 times.
9216 for ( int32_t q = 0; q < 2; q++ )
8901 {
8902
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(itemsbuf[i].sprite_initiala[q],f))
8903 {
8904 new_return(89);
8905 }
8906
8907 6144 }
8908
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(itemsbuf[i].sprite_script,f))
8909 {
8910 new_return(90);
8911 }
8912
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(itemsbuf[i].pickupflag,f))
8913 {
8914 new_return(91);
8915 }
8916
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 std::string dispname(itemsbuf[i].display_name);
8917
2/4
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3072 times.
✗ Branch 3 not taken.
3072 if(!p_putcstr(dispname,f))
8918 new_return(92);
8919
2/2
✓ Branch 0 taken 15360 times.
✓ Branch 1 taken 3072 times.
18432 for(int q = 0; q < BURNSPR_MAX; ++q)
8920 {
8921
2/4
✓ Branch 0 taken 15360 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15360 times.
✗ Branch 3 not taken.
15360 if(!p_putc(itemsbuf[i].burnsprs[q], f))
8922 new_return(93);
8923
2/4
✓ Branch 0 taken 15360 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15360 times.
✗ Branch 3 not taken.
15360 if(!p_putc(itemsbuf[i].light_rads[q], f))
8924 new_return(94);
8925 15360 }
8926 3072 }
8927
8928
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
8929 {
8930 6 section_size=writesize;
8931 6 }
8932 12 }
8933
8934
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
8935 {
8936 char ebuf[80];
8937 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8938 jwin_alert("Error: writeitems()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8939 }
8940
8941 6 new_return(0);
8942 }
8943
8944 6 int32_t writeweapons(PACKFILE *f, zquestheader *Header)
8945 {
8946 //these are here to bypass compiler warnings about unused arguments
8947 6 Header=Header;
8948
8949 6 dword section_id=ID_WEAPONS;
8950 6 dword section_version=V_WEAPONS;
8951 6 dword section_cversion=CV_WEAPONS;
8952 6 dword section_size = 0;
8953
8954 //section id
8955
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
8956 {
8957 new_return(1);
8958 }
8959
8960 //section version info
8961
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
8962 {
8963 new_return(2);
8964 }
8965
8966
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
8967 {
8968 new_return(3);
8969 }
8970
8971
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8972 {
8973 12 fake_pack_writing=(writecycle==0);
8974
8975 //section size
8976
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
8977 {
8978 new_return(4);
8979 }
8980
8981 12 writesize=0;
8982
8983 //finally... section data
8984
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(MAXWPNS,f))
8985 {
8986 new_return(5);
8987 }
8988
8989
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXWPNS; i++)
8990 {
8991
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!pfwrite((char *)weapon_string[i], 64, f))
8992 {
8993 new_return(5);
8994 }
8995 3072 }
8996
8997
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXWPNS; i++)
8998 {
8999
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].misc,f))
9000 {
9001 new_return(7);
9002 }
9003
9004
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].csets,f))
9005 {
9006 new_return(8);
9007 }
9008
9009
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].frames,f))
9010 {
9011 new_return(9);
9012 }
9013
9014
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].speed,f))
9015 {
9016 new_return(10);
9017 }
9018
9019
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_putc(wpnsbuf[i].type,f))
9020 {
9021 new_return(11);
9022 }
9023
9024
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputw(wpnsbuf[i].script,f))
9025 {
9026 new_return(12);
9027 }
9028
9029
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(!p_iputl(wpnsbuf[i].tile,f))
9030 {
9031 new_return(12);
9032 }
9033 3072 }
9034
9035
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
9036 {
9037 6 section_size=writesize;
9038 6 }
9039 12 }
9040
9041
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
9042 {
9043 char ebuf[80];
9044 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9045 jwin_alert("Error: writeweapons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9046 }
9047
9048 6 new_return(0);
9049 }
9050
9051 4080 int32_t writemapscreen(PACKFILE *f, int32_t i, int32_t j)
9052 {
9053
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4080 times.
4080 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
9054 return qe_invalid;
9055
9056 4080 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
9057 4080 bool is_0x80_screen = j >= 0x80;
9058
9059
1/2
✓ Branch 0 taken 4080 times.
✗ Branch 1 not taken.
4080 if(!p_putc(screen.valid,f))
9060 return qe_invalid;
9061
2/2
✓ Branch 0 taken 2082 times.
✓ Branch 1 taken 1998 times.
4080 if(!(screen.valid & mVALID))
9062 1998 return qe_OK;
9063 //Calculate what needs writing
9064 2082 uint32_t scr_has_flags = 0;
9065
4/8
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2080 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
2082 if(screen.guytile || screen.guy || screen.roomflags || screen.str
9066
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 || screen.room || screen.catchall)
9067 2082 scr_has_flags |= SCRHAS_ROOMDATA;
9068
7/8
✓ Branch 0 taken 1800 times.
✓ Branch 1 taken 282 times.
✓ Branch 2 taken 120 times.
✓ Branch 3 taken 1680 times.
✓ Branch 4 taken 112 times.
✓ Branch 5 taken 8 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 112 times.
2082 if(screen.hasitem || (is_0x80_screen && (screen.itemx||screen.itemy)))
9069 290 scr_has_flags |= SCRHAS_ITEM;
9070
3/4
✓ Branch 0 taken 2064 times.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2064 times.
2082 if((screen.warpreturnc&0x00FF) || screen.tilewarpoverlayflags)
9071 18 scr_has_flags |= SCRHAS_TWARP;
9072
2/2
✓ Branch 0 taken 1896 times.
✓ Branch 1 taken 7754 times.
9650 else for(auto q = 0; q < 4; ++q)
9073 {
9074
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7586 times.
15340 if(screen.tilewarptype[q]
9075
2/2
✓ Branch 0 taken 7588 times.
✓ Branch 1 taken 166 times.
7754 || screen.tilewarpdmap[q]
9076
2/2
✓ Branch 0 taken 7586 times.
✓ Branch 1 taken 2 times.
7588 || screen.tilewarpscr[q])
9077 {
9078 168 scr_has_flags |= SCRHAS_TWARP;
9079 168 break;
9080 }
9081 7586 }
9082
3/4
✓ Branch 0 taken 2078 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2076 times.
2082 if((screen.warpreturnc&0xFF00) || screen.sidewarpindex
9083
2/2
✓ Branch 0 taken 2076 times.
✓ Branch 1 taken 2 times.
2078 || screen.sidewarpoverlayflags)
9084 6 scr_has_flags |= SCRHAS_SWARP;
9085
2/2
✓ Branch 0 taken 636 times.
✓ Branch 1 taken 3984 times.
4620 else for(auto q = 0; q < 4; ++q)
9086 {
9087
2/2
✓ Branch 0 taken 2544 times.
✓ Branch 1 taken 8 times.
6536 if(screen.sidewarptype[q] != wtSCROLL
9088
2/2
✓ Branch 0 taken 2560 times.
✓ Branch 1 taken 1424 times.
3984 || screen.sidewarpdmap[q]
9089
2/2
✓ Branch 0 taken 2552 times.
✓ Branch 1 taken 8 times.
2560 || screen.sidewarpscr[q])
9090 {
9091 1440 scr_has_flags |= SCRHAS_SWARP;
9092 1440 break;
9093 }
9094 2544 }
9095
3/4
✓ Branch 0 taken 2038 times.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2038 times.
2082 if(screen.warparrivalx || screen.warparrivaly)
9096 44 scr_has_flags |= SCRHAS_WARPRET;
9097
2/2
✓ Branch 0 taken 1450 times.
✓ Branch 1 taken 6388 times.
7838 else for(auto q = 0; q < 4; ++q)
9098 {
9099
3/4
✓ Branch 0 taken 5800 times.
✓ Branch 1 taken 588 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5800 times.
6388 if(screen.warpreturnx[q] || screen.warpreturny[q])
9100 {
9101 588 scr_has_flags |= SCRHAS_WARPRET;
9102 588 break;
9103 }
9104 5800 }
9105
9106
2/4
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2082 times.
2082 if(screen.hidelayers || screen.hidescriptlayers)
9107 scr_has_flags |= SCRHAS_LAYERS;
9108
2/2
✓ Branch 0 taken 1890 times.
✓ Branch 1 taken 11548 times.
13438 else for(auto q = 0; q < 6; ++q)
9109 {
9110
4/4
✓ Branch 0 taken 11366 times.
✓ Branch 1 taken 182 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 11356 times.
11548 if(screen.layermap[q] || screen.layerscreen[q]
9111
1/2
✓ Branch 0 taken 11366 times.
✗ Branch 1 not taken.
11366 || screen.layeropacity[q]!=255)
9112 {
9113 192 scr_has_flags |= SCRHAS_LAYERS;
9114 192 break;
9115 }
9116 11356 }
9117
9118
2/2
✓ Branch 0 taken 2078 times.
✓ Branch 1 taken 4 times.
2082 if(screen.exitdir)
9119 4 scr_has_flags |= SCRHAS_MAZE;
9120
2/2
✓ Branch 0 taken 2078 times.
✓ Branch 1 taken 8312 times.
10390 else for(auto q = 0; q < 4; ++q)
9121 {
9122
1/2
✓ Branch 0 taken 8312 times.
✗ Branch 1 not taken.
8312 if(screen.path[q])
9123 {
9124 scr_has_flags |= SCRHAS_MAZE;
9125 break;
9126 }
9127 8312 }
9128
9129
4/4
✓ Branch 0 taken 1848 times.
✓ Branch 1 taken 234 times.
✓ Branch 2 taken 238 times.
✓ Branch 3 taken 752 times.
3072 if(screen.door_combo_set || screen.stairx
9130
3/4
✓ Branch 0 taken 1820 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 1820 times.
✗ Branch 3 not taken.
1848 || screen.stairy || screen.undercombo
9131
2/2
✓ Branch 0 taken 990 times.
✓ Branch 1 taken 830 times.
1820 || screen.undercset)
9132 1330 scr_has_flags |= SCRHAS_D_S_U;
9133
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 812 times.
832 else for(auto q = 0; q < 4; ++q)
9134 {
9135
2/2
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 732 times.
812 if(screen.door[q] != dNONE)
9136 {
9137 732 scr_has_flags |= SCRHAS_D_S_U;
9138 732 break;
9139 }
9140 80 }
9141
9142
2/2
✓ Branch 0 taken 1822 times.
✓ Branch 1 taken 260 times.
3540 if(screen.flags || screen.flags2
9143
4/4
✓ Branch 0 taken 1736 times.
✓ Branch 1 taken 86 times.
✓ Branch 2 taken 1702 times.
✓ Branch 3 taken 34 times.
1822 || screen.flags3 || screen.flags4
9144
4/4
✓ Branch 0 taken 1688 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 1674 times.
✓ Branch 3 taken 14 times.
1702 || screen.flags5 || screen.flags6
9145
4/4
✓ Branch 0 taken 1466 times.
✓ Branch 1 taken 208 times.
✓ Branch 2 taken 1458 times.
✓ Branch 3 taken 8 times.
1674 || screen.flags7 || screen.flags8
9146
2/4
✓ Branch 0 taken 1458 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1458 times.
✗ Branch 3 not taken.
1458 || screen.flags9 || screen.flags10
9147
1/2
✓ Branch 0 taken 1458 times.
✗ Branch 1 not taken.
1458 || screen.enemyflags)
9148 2082 scr_has_flags |= SCRHAS_FLAGS;
9149
9150
2/2
✓ Branch 0 taken 2032 times.
✓ Branch 1 taken 50 times.
2082 if(screen.pattern)
9151 50 scr_has_flags |= SCRHAS_ENEMY;
9152
2/2
✓ Branch 0 taken 1392 times.
✓ Branch 1 taken 14560 times.
15952 else for(auto q = 0; q < 10; ++q)
9153 {
9154
2/2
✓ Branch 0 taken 13920 times.
✓ Branch 1 taken 640 times.
14560 if(screen.enemy[q])
9155 {
9156 640 scr_has_flags |= SCRHAS_ENEMY;
9157 640 break;
9158 }
9159 13920 }
9160
9161
2/4
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2076 times.
4158 if(screen.noreset || screen.nocarry
9162
3/4
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2076 times.
✓ Branch 3 taken 6 times.
2082 || screen.nextmap || screen.nextscr)
9163 6 scr_has_flags |= SCRHAS_CARRY;
9164
9165
3/4
✓ Branch 0 taken 2064 times.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2064 times.
2082 if(screen.script || screen.preloadscript)
9166 18 scr_has_flags |= SCRHAS_SCRIPT;
9167
2/2
✓ Branch 0 taken 2064 times.
✓ Branch 1 taken 16512 times.
18576 else for(auto q = 0; q < 8; ++q)
9168 {
9169
1/2
✓ Branch 0 taken 16512 times.
✗ Branch 1 not taken.
16512 if(screen.screeninitd[q])
9170 {
9171 scr_has_flags |= SCRHAS_SCRIPT;
9172 break;
9173 }
9174 16512 }
9175
9176
2/2
✓ Branch 0 taken 2082 times.
✓ Branch 1 taken 20820 times.
22902 for(auto q = 0; q < 10; ++q)
9177 {
9178
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20820 times.
41640 if(screen.npcstrings[q]
9179
1/2
✓ Branch 0 taken 20820 times.
✗ Branch 1 not taken.
20820 || screen.new_items[q]
9180
1/2
✓ Branch 0 taken 20820 times.
✗ Branch 1 not taken.
20820 || screen.new_item_x[q]
9181
1/2
✓ Branch 0 taken 20820 times.
✗ Branch 1 not taken.
20820 || screen.new_item_y[q])
9182 {
9183 scr_has_flags |= SCRHAS_UNUSED;
9184 break;
9185 }
9186 20820 }
9187
9188
2/2
✓ Branch 0 taken 758 times.
✓ Branch 1 taken 99352 times.
100110 for(auto q = 0; q < 128; ++q)
9189 {
9190
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 98028 times.
197380 if(screen.secretcombo[q]
9191
2/2
✓ Branch 0 taken 98030 times.
✓ Branch 1 taken 1322 times.
99352 || screen.secretcset[q]
9192
2/2
✓ Branch 0 taken 98028 times.
✓ Branch 1 taken 2 times.
98030 || screen.secretflag[q])
9193 {
9194 1324 scr_has_flags |= SCRHAS_SECRETS;
9195 1324 break;
9196 }
9197 98028 }
9198
9199
2/2
✓ Branch 0 taken 172 times.
✓ Branch 1 taken 40228 times.
40400 for(auto q = 0; q < 176; ++q)
9200 {
9201
4/4
✓ Branch 0 taken 38408 times.
✓ Branch 1 taken 1820 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 38318 times.
40228 if(screen.data[q] || screen.cset[q]
9202
2/2
✓ Branch 0 taken 38320 times.
✓ Branch 1 taken 88 times.
38408 || screen.sflag[q])
9203 {
9204 1910 scr_has_flags |= SCRHAS_COMBOFLAG;
9205 1910 break;
9206 }
9207 38318 }
9208
9209
2/2
✓ Branch 0 taken 786 times.
✓ Branch 1 taken 1296 times.
2082 if(screen.color || screen.csensitive != 1
9210
3/4
✓ Branch 0 taken 786 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 752 times.
✓ Branch 3 taken 34 times.
786 || screen.oceansfx || screen.bosssfx
9211
2/4
✓ Branch 0 taken 752 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 752 times.
752 || screen.secretsfx || screen.holdupsfx
9212 || screen.timedwarptics || screen.screen_midi != -1
9213 || screen.lens_layer || screen.lens_show || screen.lens_hide)
9214 2082 scr_has_flags |= SCRHAS_MISC;
9215
9216
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputl(scr_has_flags,f))
9217 return qe_invalid;
9218
9219 //Write stuff
9220
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2082 times.
2082 if(scr_has_flags & SCRHAS_ROOMDATA)
9221 {
9222
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.guy,f))
9223 return qe_invalid;
9224
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputl(screen.guytile,f))
9225 return qe_invalid;
9226
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.guycs,f))
9227 return qe_invalid;
9228
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.roomflags,f))
9229 return qe_invalid;
9230
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.str,f))
9231 return qe_invalid;
9232
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.room,f))
9233 return qe_invalid;
9234
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.catchall,f))
9235 return qe_invalid;
9236 2082 }
9237
2/2
✓ Branch 0 taken 1792 times.
✓ Branch 1 taken 290 times.
2082 if(scr_has_flags & SCRHAS_ITEM)
9238 {
9239
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 if(!p_putc(screen.item,f))
9240 return qe_invalid;
9241
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 if(!p_putc(screen.hasitem,f))
9242 return qe_invalid;
9243
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 if(!p_putc(screen.itemx,f))
9244 return qe_invalid;
9245
1/2
✓ Branch 0 taken 290 times.
✗ Branch 1 not taken.
290 if(!p_putc(screen.itemy,f))
9246 return qe_invalid;
9247 290 }
9248
2/2
✓ Branch 0 taken 582 times.
✓ Branch 1 taken 1500 times.
2082 if(scr_has_flags & (SCRHAS_SWARP|SCRHAS_TWARP))
9249 {
9250
1/2
✓ Branch 0 taken 1500 times.
✗ Branch 1 not taken.
1500 if(!p_iputw(screen.warpreturnc,f))
9251 return qe_invalid;
9252 1500 }
9253
2/2
✓ Branch 0 taken 1896 times.
✓ Branch 1 taken 186 times.
2082 if(scr_has_flags & SCRHAS_TWARP)
9254 {
9255
2/2
✓ Branch 0 taken 744 times.
✓ Branch 1 taken 186 times.
930 for(int32_t k=0; k<4; k++)
9256 {
9257
1/2
✓ Branch 0 taken 744 times.
✗ Branch 1 not taken.
744 if(!p_putc(screen.tilewarptype[k],f))
9258 return qe_invalid;
9259 744 }
9260
2/2
✓ Branch 0 taken 744 times.
✓ Branch 1 taken 186 times.
930 for(int32_t k=0; k<4; k++)
9261 {
9262
1/2
✓ Branch 0 taken 744 times.
✗ Branch 1 not taken.
744 if(!p_iputw(screen.tilewarpdmap[k],f))
9263 return qe_invalid;
9264 744 }
9265
9266
2/2
✓ Branch 0 taken 744 times.
✓ Branch 1 taken 186 times.
930 for(int32_t k=0; k<4; k++)
9267 {
9268
1/2
✓ Branch 0 taken 744 times.
✗ Branch 1 not taken.
744 if(!p_putc(screen.tilewarpscr[k],f))
9269 return qe_invalid;
9270 744 }
9271
9272
1/2
✓ Branch 0 taken 186 times.
✗ Branch 1 not taken.
186 if(!p_putc(screen.tilewarpoverlayflags,f))
9273 return qe_invalid;
9274 186 }
9275
2/2
✓ Branch 0 taken 636 times.
✓ Branch 1 taken 1446 times.
2082 if(scr_has_flags & SCRHAS_SWARP)
9276 {
9277
2/2
✓ Branch 0 taken 5784 times.
✓ Branch 1 taken 1446 times.
7230 for(int32_t k=0; k<4; k++)
9278 {
9279
1/2
✓ Branch 0 taken 5784 times.
✗ Branch 1 not taken.
5784 if(!p_putc(screen.sidewarptype[k],f))
9280 return qe_invalid;
9281 5784 }
9282
2/2
✓ Branch 0 taken 5784 times.
✓ Branch 1 taken 1446 times.
7230 for(int32_t k=0; k<4; k++)
9283 {
9284
1/2
✓ Branch 0 taken 5784 times.
✗ Branch 1 not taken.
5784 if(!p_iputw(screen.sidewarpdmap[k],f))
9285 return qe_invalid;
9286 5784 }
9287
9288
2/2
✓ Branch 0 taken 5784 times.
✓ Branch 1 taken 1446 times.
7230 for(int32_t k=0; k<4; k++)
9289 {
9290
1/2
✓ Branch 0 taken 5784 times.
✗ Branch 1 not taken.
5784 if(!p_putc(screen.sidewarpscr[k],f))
9291 return qe_invalid;
9292 5784 }
9293
9294
1/2
✓ Branch 0 taken 1446 times.
✗ Branch 1 not taken.
1446 if(!p_putc(screen.sidewarpoverlayflags,f))
9295 return qe_invalid;
9296
1/2
✓ Branch 0 taken 1446 times.
✗ Branch 1 not taken.
1446 if(!p_putc(screen.sidewarpindex,f))
9297 return qe_invalid;
9298 1446 }
9299
2/2
✓ Branch 0 taken 1450 times.
✓ Branch 1 taken 632 times.
2082 if(scr_has_flags & SCRHAS_WARPRET)
9300 {
9301
2/2
✓ Branch 0 taken 2528 times.
✓ Branch 1 taken 632 times.
3160 for(int32_t k=0; k<4; k++)
9302 {
9303
1/2
✓ Branch 0 taken 2528 times.
✗ Branch 1 not taken.
2528 if(!p_putc(screen.warpreturnx[k],f))
9304 return qe_invalid;
9305 2528 }
9306
2/2
✓ Branch 0 taken 2528 times.
✓ Branch 1 taken 632 times.
3160 for(int32_t k=0; k<4; k++)
9307 {
9308
1/2
✓ Branch 0 taken 2528 times.
✗ Branch 1 not taken.
2528 if(!p_putc(screen.warpreturny[k],f))
9309 return qe_invalid;
9310 2528 }
9311
1/2
✓ Branch 0 taken 632 times.
✗ Branch 1 not taken.
632 if(!p_putc(screen.warparrivalx,f))
9312 return qe_invalid;
9313
1/2
✓ Branch 0 taken 632 times.
✗ Branch 1 not taken.
632 if(!p_putc(screen.warparrivaly,f))
9314 return qe_invalid;
9315 632 }
9316
2/2
✓ Branch 0 taken 1890 times.
✓ Branch 1 taken 192 times.
2082 if(scr_has_flags & SCRHAS_LAYERS)
9317 {
9318
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 192 times.
1344 for(int32_t k=0; k<6; k++)
9319 {
9320
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if(!p_putc(screen.layermap[k],f))
9321 return qe_invalid;
9322 1152 }
9323
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 192 times.
1344 for(int32_t k=0; k<6; k++)
9324 {
9325
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if(!p_putc(screen.layerscreen[k],f))
9326 return qe_invalid;
9327 1152 }
9328
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 192 times.
1344 for(int32_t k=0; k<6; k++)
9329 {
9330
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if(!p_putc(screen.layeropacity[k],f))
9331 return qe_invalid;
9332 1152 }
9333
1/2
✓ Branch 0 taken 192 times.
✗ Branch 1 not taken.
192 if(!p_putc(screen.hidelayers,f))
9334 return qe_invalid;
9335
1/2
✓ Branch 0 taken 192 times.
✗ Branch 1 not taken.
192 if(!p_putc(screen.hidescriptlayers,f))
9336 return qe_invalid;
9337 192 }
9338
2/2
✓ Branch 0 taken 2078 times.
✓ Branch 1 taken 4 times.
2082 if(scr_has_flags & SCRHAS_MAZE)
9339 {
9340
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 4 times.
20 for(int32_t k=0; k<4; k++)
9341 {
9342
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!p_putc(screen.path[k],f))
9343 return qe_invalid;
9344 16 }
9345
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_putc(screen.exitdir,f))
9346 return qe_invalid;
9347 4 }
9348
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 2062 times.
2082 if(scr_has_flags & SCRHAS_D_S_U)
9349 {
9350
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_iputw(screen.door_combo_set,f))
9351 return qe_invalid;
9352
2/2
✓ Branch 0 taken 8248 times.
✓ Branch 1 taken 2062 times.
10310 for(int32_t k=0; k<4; k++)
9353 {
9354
1/2
✓ Branch 0 taken 8248 times.
✗ Branch 1 not taken.
8248 if(!p_putc(screen.door[k],f))
9355 return qe_invalid;
9356 8248 }
9357
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_putc(screen.stairx,f))
9358 return qe_invalid;
9359
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_putc(screen.stairy,f))
9360 return qe_invalid;
9361
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_iputw(screen.undercombo,f))
9362 return qe_invalid;
9363
1/2
✓ Branch 0 taken 2062 times.
✗ Branch 1 not taken.
2062 if(!p_putc(screen.undercset,f))
9364 return qe_invalid;
9365 2062 }
9366
2/2
✓ Branch 0 taken 1336 times.
✓ Branch 1 taken 746 times.
2082 if(scr_has_flags & SCRHAS_FLAGS)
9367 {
9368
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags,f))
9369 return qe_invalid;
9370
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags2,f))
9371 return qe_invalid;
9372
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags3,f))
9373 return qe_invalid;
9374
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags4,f))
9375 return qe_invalid;
9376
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags5,f))
9377 return qe_invalid;
9378
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags6,f))
9379 return qe_invalid;
9380
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags7,f))
9381 return qe_invalid;
9382
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags8,f))
9383 return qe_invalid;
9384
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags9,f))
9385 return qe_invalid;
9386
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.flags10,f))
9387 return qe_invalid;
9388
1/2
✓ Branch 0 taken 746 times.
✗ Branch 1 not taken.
746 if(!p_putc(screen.enemyflags,f))
9389 return qe_invalid;
9390 746 }
9391
2/2
✓ Branch 0 taken 1392 times.
✓ Branch 1 taken 690 times.
2082 if(scr_has_flags & SCRHAS_ENEMY)
9392 {
9393
2/2
✓ Branch 0 taken 6900 times.
✓ Branch 1 taken 690 times.
7590 for(int32_t k=0; k<10; k++)
9394 {
9395
1/2
✓ Branch 0 taken 6900 times.
✗ Branch 1 not taken.
6900 if(!p_iputw(screen.enemy[k],f))
9396 return qe_invalid;
9397 6900 }
9398
1/2
✓ Branch 0 taken 690 times.
✗ Branch 1 not taken.
690 if(!p_putc(screen.pattern,f))
9399 return qe_invalid;
9400 690 }
9401
2/2
✓ Branch 0 taken 2076 times.
✓ Branch 1 taken 6 times.
2082 if(scr_has_flags & SCRHAS_CARRY)
9402 {
9403
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(screen.noreset,f))
9404 return qe_invalid;
9405
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(screen.nocarry,f))
9406 return qe_invalid;
9407
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_putc(screen.nextmap,f))
9408 return qe_invalid;
9409
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_putc(screen.nextscr,f))
9410 return qe_invalid;
9411 6 }
9412
2/2
✓ Branch 0 taken 2064 times.
✓ Branch 1 taken 18 times.
2082 if(scr_has_flags & SCRHAS_SCRIPT)
9413 {
9414
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(screen.script,f))
9415 return qe_invalid;
9416
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(screen.preloadscript,f))
9417 return qe_invalid;
9418
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 18 times.
162 for ( int32_t q = 0; q < 8; q++ )
9419 {
9420
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(!p_iputl(screen.screeninitd[q],f))
9421 return qe_invalid;
9422 144 }
9423 18 }
9424
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(scr_has_flags & SCRHAS_UNUSED)
9425 {
9426 for ( int32_t q = 0; q < 10; q++ )
9427 {
9428 if(!p_iputl(screen.npcstrings[q],f))
9429 return qe_invalid;
9430 }
9431 for ( int32_t q = 0; q < 10; q++ )
9432 {
9433 if(!p_iputw(screen.new_items[q],f))
9434 return qe_invalid;
9435 }
9436 for ( int32_t q = 0; q < 10; q++ )
9437 {
9438 if(!p_iputw(screen.new_item_x[q],f))
9439 return qe_invalid;
9440 }
9441 for ( int32_t q = 0; q < 10; q++ )
9442 {
9443 if(!p_iputw(screen.new_item_y[q],f))
9444 return qe_invalid;
9445 }
9446 }
9447
2/2
✓ Branch 0 taken 758 times.
✓ Branch 1 taken 1324 times.
2082 if(scr_has_flags & SCRHAS_SECRETS)
9448 {
9449
2/2
✓ Branch 0 taken 169472 times.
✓ Branch 1 taken 1324 times.
170796 for(int32_t k=0; k<128; k++)
9450 {
9451
1/2
✓ Branch 0 taken 169472 times.
✗ Branch 1 not taken.
169472 if(!p_iputw(screen.secretcombo[k],f))
9452 return qe_invalid;
9453 169472 }
9454
9455
2/2
✓ Branch 0 taken 169472 times.
✓ Branch 1 taken 1324 times.
170796 for(int32_t k=0; k<128; k++)
9456 {
9457
1/2
✓ Branch 0 taken 169472 times.
✗ Branch 1 not taken.
169472 if(!p_putc(screen.secretcset[k],f))
9458 return qe_invalid;
9459 169472 }
9460
9461
2/2
✓ Branch 0 taken 169472 times.
✓ Branch 1 taken 1324 times.
170796 for(int32_t k=0; k<128; k++)
9462 {
9463
1/2
✓ Branch 0 taken 169472 times.
✗ Branch 1 not taken.
169472 if(!p_putc(screen.secretflag[k],f))
9464 return qe_invalid;
9465 169472 }
9466 1324 }
9467
2/2
✓ Branch 0 taken 172 times.
✓ Branch 1 taken 1910 times.
2082 if(scr_has_flags & SCRHAS_COMBOFLAG)
9468 {
9469
2/2
✓ Branch 0 taken 336160 times.
✓ Branch 1 taken 1910 times.
338070 for(int32_t k=0; k<176; ++k)
9470 {
9471
1/2
✓ Branch 0 taken 336160 times.
✗ Branch 1 not taken.
336160 if(!p_iputw(screen.data[k],f))
9472 return qe_invalid;
9473 336160 }
9474
2/2
✓ Branch 0 taken 336160 times.
✓ Branch 1 taken 1910 times.
338070 for(int32_t k=0; k<176; ++k)
9475 {
9476
1/2
✓ Branch 0 taken 336160 times.
✗ Branch 1 not taken.
336160 if(!p_putc(screen.sflag[k],f))
9477 return qe_invalid;
9478 336160 }
9479
2/2
✓ Branch 0 taken 336160 times.
✓ Branch 1 taken 1910 times.
338070 for(int32_t k=0; k<176; ++k)
9480 {
9481
1/2
✓ Branch 0 taken 336160 times.
✗ Branch 1 not taken.
336160 if(!p_putc(screen.cset[k],f))
9482 return qe_invalid;
9483 336160 }
9484 1910 }
9485
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2082 times.
2082 if(scr_has_flags & SCRHAS_MISC)
9486 {
9487
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.color,f))
9488 return qe_invalid;
9489
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.csensitive,f))
9490 return qe_invalid;
9491
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.oceansfx,f))
9492 return qe_invalid;
9493
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.bosssfx,f))
9494 return qe_invalid;
9495
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.secretsfx,f))
9496 return qe_invalid;
9497
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.holdupsfx,f))
9498 return qe_invalid;
9499
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.timedwarptics,f))
9500 return qe_invalid;
9501
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(screen.screen_midi,f))
9502 return qe_invalid;
9503
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.lens_layer,f))
9504 return qe_invalid;
9505
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putc(screen.lens_show,f))
9506 return qe_invalid;
9507
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2082 times.
2082 if(!p_putc(screen.lens_hide,f))
9508 return qe_invalid;
9509 2082 }
9510
9511 2082 dword numffc = screen.numFFC();
9512
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_iputw(numffc,f))
9513 return qe_invalid;
9514
2/2
✓ Branch 0 taken 45816 times.
✓ Branch 1 taken 2082 times.
47898 for(int32_t k=0; k<numffc; ++k)
9515 {
9516 45816 ffcdata const& tempffc = screen.ffcs[k];
9517
9518
1/2
✓ Branch 0 taken 45816 times.
✗ Branch 1 not taken.
45816 if(!p_iputw(tempffc.data,f))
9519 return qe_invalid;
9520
9521
2/2
✓ Branch 0 taken 44726 times.
✓ Branch 1 taken 1090 times.
45816 if(!tempffc.data) //don't save the rest of the ffc
9522 44726 continue;
9523
9524
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.cset,f))
9525 return qe_invalid;
9526
9527
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputw(tempffc.delay,f))
9528 return qe_invalid;
9529
9530
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.x,f))
9531 return qe_invalid;
9532
9533
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.y,f))
9534 return qe_invalid;
9535
9536
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.vx,f))
9537 return qe_invalid;
9538
9539
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.vy,f))
9540 return qe_invalid;
9541
9542
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.ax,f))
9543 return qe_invalid;
9544
9545
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputzf(tempffc.ay,f))
9546 return qe_invalid;
9547
9548
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.link,f))
9549 return qe_invalid;
9550
9551
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputl(tempffc.hit_width,f))
9552 return qe_invalid;
9553
9554
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputl(tempffc.hit_height,f))
9555 return qe_invalid;
9556
9557
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.txsz,f))
9558 return qe_invalid;
9559
9560
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.tysz,f))
9561 return qe_invalid;
9562
9563
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputl(tempffc.flags,f))
9564 return qe_invalid;
9565
9566
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_iputw(tempffc.script,f))
9567 return qe_invalid;
9568
9569
2/2
✓ Branch 0 taken 8720 times.
✓ Branch 1 taken 1090 times.
9810 for(auto q = 0; q < 8; ++q)
9570 {
9571
1/2
✓ Branch 0 taken 8720 times.
✗ Branch 1 not taken.
8720 if(!p_iputl(tempffc.initd[q],f))
9572 return qe_invalid;
9573 8720 }
9574
9575
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.inita[0]/10000,f))
9576 return qe_invalid;
9577
9578
1/2
✓ Branch 0 taken 1090 times.
✗ Branch 1 not taken.
1090 if(!p_putc(tempffc.inita[1]/10000,f))
9579 return qe_invalid;
9580 1090 }
9581
9582
1/2
✓ Branch 0 taken 2082 times.
✗ Branch 1 not taken.
2082 if(!p_putlstr(screen.usr_notes, f))
9583 return qe_invalid;
9584
9585 2082 return qe_OK;
9586 4080 }
9587
9588 6 int32_t writemaps(PACKFILE *f, zquestheader *)
9589 {
9590 6 dword section_id=ID_MAPS;
9591 6 dword section_version=V_MAPS;
9592 6 dword section_cversion=CV_MAPS;
9593 6 dword section_size = 0;
9594
9595 //section id
9596
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
9597 {
9598 new_return(1);
9599 }
9600
9601 //section version info
9602
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
9603 {
9604 new_return(2);
9605 }
9606
9607
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
9608 {
9609 new_return(3);
9610 }
9611
9612
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9613 {
9614 12 fake_pack_writing=(writecycle==0);
9615
9616 //section size
9617
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
9618 {
9619 new_return(4);
9620 }
9621
9622 12 writesize=0;
9623
9624
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(map_count,f))
9625 {
9626 new_return(5);
9627 }
9628 12 map_autolayers.resize(map_count*6);
9629
4/4
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 30 times.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 12 times.
42 for(int32_t i=0; i<map_count && i<MAXMAPS; i++)
9630 {
9631 30 byte valid = 0;
9632
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 240 times.
240 for(int32_t j=0; j<MAPSCRS; j++)
9633 {
9634
1/2
✓ Branch 0 taken 240 times.
✗ Branch 1 not taken.
240 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
9635 break;
9636 240 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
9637
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 210 times.
240 if(screen.valid & mVALID)
9638 {
9639 30 valid = 1;
9640 30 break;
9641 }
9642 210 }
9643
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(!p_putc(valid,f))
9644 {
9645 new_return(6);
9646 }
9647
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(!valid) continue;
9648
9649 { //per-map info
9650
2/2
✓ Branch 0 taken 180 times.
✓ Branch 1 taken 30 times.
210 for(int q = 0; q < 6; ++q)
9651 {
9652 180 size_t ind = i*6+q;
9653
1/2
✓ Branch 0 taken 180 times.
✗ Branch 1 not taken.
180 if(!p_iputw(map_autolayers[ind],f))
9654 new_return(7);
9655 180 }
9656 }
9657
9658
2/2
✓ Branch 0 taken 4080 times.
✓ Branch 1 taken 30 times.
4110 for(int32_t j=0; j<MAPSCRS; j++)
9659 4080 writemapscreen(f,i,j);
9660 30 }
9661
9662
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
9663 {
9664 6 section_size=writesize;
9665 6 }
9666 12 }
9667
9668
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
9669 {
9670 char ebuf[80];
9671 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9672 jwin_alert("Error: writemaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9673 }
9674
9675 6 new_return(0);
9676 }
9677
9678 int32_t writecombo_loop(PACKFILE *f, word section_version, newcombo const& tmp_cmb)
9679 {
9680 //Check what needs writing
9681 byte combo_has_flags = 0;
9682 383638 for(auto q = 0; q < 8; ++q)
9683 {
9684 767276 if(tmp_cmb.attribytes[q] || tmp_cmb.attrishorts[q]
9685 383638 || (q < 4 && tmp_cmb.attributes[q]))
9686 {
9687 combo_has_flags |= CHAS_ATTRIB;
9688 break;
9689 }
9690 383638 }
9691
3/4
✓ Branch 0 taken 96864 times.
✓ Branch 1 taken 96864 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 96836 times.
96836 if(tmp_cmb.triggerflags[0] || tmp_cmb.triggerflags[1]
9692
3/4
✓ Branch 0 taken 96862 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 96862 times.
✗ Branch 3 not taken.
96864 || tmp_cmb.triggerflags[2] || tmp_cmb.triggerflags[3]
9693
3/4
✓ Branch 0 taken 96860 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96862 || tmp_cmb.triggerflags[4] || tmp_cmb.triggerflags[5]
9694
2/4
✓ Branch 0 taken 96860 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.triggerlevel || tmp_cmb.trig_lstate
9695
2/4
✓ Branch 0 taken 96860 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.trig_gstate || tmp_cmb.trig_statetime
9696
2/4
✓ Branch 0 taken 96860 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.triggerbtn || tmp_cmb.triggeritem
9697
2/4
✓ Branch 0 taken 96860 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96860 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.trigtimer || tmp_cmb.trigsfx
9698
3/4
✓ Branch 0 taken 96836 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96860 || tmp_cmb.trigchange || tmp_cmb.trigprox
9699
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trigctr || tmp_cmb.trigctramnt
9700
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.triglbeam || tmp_cmb.trigcschange
9701
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.spawnitem || tmp_cmb.spawnenemy
9702
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.exstate > -1 || tmp_cmb.spawnip
9703
1/2
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
96836 || tmp_cmb.exdoor_dir > -1
9704
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trigcopycat || tmp_cmb.trigcooldown
9705
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_genscr || tmp_cmb.trig_group
9706
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_group_val || tmp_cmb.trig_levelitems
9707
1/2
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
96836 || tmp_cmb.trigdmlevel > -1
9708
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.triglvlpalette > -1 || tmp_cmb.trigbosspalette > -1
9709
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trigquaketime > -1 || tmp_cmb.trigwavytime > -1
9710
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_swjinxtime > -2 || tmp_cmb.trig_itmjinxtime > -2
9711
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.trig_stuntime > -2 || tmp_cmb.trig_bunnytime > -2
9712
1/2
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
96836 || tmp_cmb.trig_pushtime != 8
9713
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.prompt_cid || tmp_cmb.prompt_cs
9714
2/4
✓ Branch 0 taken 96836 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96836 times.
✗ Branch 3 not taken.
96836 || tmp_cmb.prompt_x != 12 || tmp_cmb.prompt_y != -8)
9715 96892 combo_has_flags |= CHAS_TRIG;
9716
2/2
✓ Branch 0 taken 290508 times.
✓ Branch 1 taken 96836 times.
387344 else for(int q = 0; q < 3; ++q)
9717
1/2
✓ Branch 0 taken 290508 times.
✗ Branch 1 not taken.
290508 if(tmp_cmb.trigtint[q])
9718 combo_has_flags |= CHAS_TRIG;
9719
4/4
✓ Branch 0 taken 96840 times.
✓ Branch 1 taken 96888 times.
✓ Branch 2 taken 96704 times.
✓ Branch 3 taken 136 times.
193728 if(tmp_cmb.usrflags || tmp_cmb.genflags)
9720 193592 combo_has_flags |= CHAS_FLAG;
9721
6/6
✓ Branch 0 taken 93610 times.
✓ Branch 1 taken 93290 times.
✓ Branch 2 taken 80124 times.
✓ Branch 3 taken 13486 times.
✓ Branch 4 taken 89494 times.
✓ Branch 5 taken 9434 times.
80380 if(tmp_cmb.frames || tmp_cmb.speed || tmp_cmb.nextcombo
9722
6/6
✓ Branch 0 taken 80100 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 80070 times.
✓ Branch 3 taken 30 times.
✓ Branch 4 taken 80060 times.
✓ Branch 5 taken 10 times.
80124 || tmp_cmb.nextcset || tmp_cmb.skipanim || tmp_cmb.skipanimy
9723
1/2
✓ Branch 0 taken 80060 times.
✗ Branch 1 not taken.
80060 || tmp_cmb.animflags)
9724 196334 combo_has_flags |= CHAS_ANIM;
9725
3/4
✓ Branch 0 taken 97004 times.
✓ Branch 1 taken 70224 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 97004 times.
26780 if(tmp_cmb.script || tmp_cmb.label.size())
9726 70224 combo_has_flags |= CHAS_SCRIPT;
9727
2/2
✓ Branch 0 taken 776032 times.
✓ Branch 1 taken 97004 times.
873036 else for(auto q = 0; q < 8; ++q)
9728 {
9729
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 776032 times.
776032 if(tmp_cmb.initd[q])
9730 {
9731 combo_has_flags |= CHAS_SCRIPT;
9732 break;
9733 }
9734 776032 }
9735
6/6
✓ Branch 0 taken 52696 times.
✓ Branch 1 taken 114532 times.
✓ Branch 2 taken 52184 times.
✓ Branch 3 taken 512 times.
✓ Branch 4 taken 70224 times.
✓ Branch 5 taken 18040 times.
219412 if(tmp_cmb.o_tile || tmp_cmb.flip || tmp_cmb.walk != 0xF0
9736
2/4
✓ Branch 0 taken 52184 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 52184 times.
✗ Branch 3 not taken.
52184 || tmp_cmb.type || tmp_cmb.csets)
9737 185268 combo_has_flags |= CHAS_BASIC;
9738
3/4
✓ Branch 0 taken 96996 times.
✓ Branch 1 taken 34136 times.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
159856 if(tmp_cmb.liftcmb || tmp_cmb.liftcs || tmp_cmb.liftdmg
9739
3/6
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 96996 times.
✗ Branch 5 not taken.
96996 || tmp_cmb.liftlvl || tmp_cmb.liftitm || tmp_cmb.liftflags
9740
3/6
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 96996 times.
✗ Branch 5 not taken.
96996 || tmp_cmb.liftgfx || tmp_cmb.liftsprite || tmp_cmb.liftsfx
9741
2/4
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
96996 || tmp_cmb.liftundercmb || tmp_cmb.liftundercs
9742
2/4
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
96996 || tmp_cmb.liftbreaksprite!=-1 || tmp_cmb.liftbreaksfx
9743
2/4
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
96996 || tmp_cmb.lifthei!=8 || tmp_cmb.lifttime!=16
9744
1/2
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
96996 || tmp_cmb.lift_parent_item)
9745 131132 combo_has_flags |= CHAS_LIFT;
9746
3/4
✓ Branch 0 taken 97004 times.
✓ Branch 1 taken 34128 times.
✓ Branch 2 taken 97004 times.
✗ Branch 3 not taken.
228128 if(tmp_cmb.speed_mult != 1 || tmp_cmb.speed_div != 1 || tmp_cmb.speed_add
9747
7/10
✓ Branch 0 taken 97004 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 97000 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 96996 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 96996 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 96996 times.
✗ Branch 9 not taken.
97004 || tmp_cmb.sfx_appear || tmp_cmb.sfx_disappear || tmp_cmb.sfx_loop || tmp_cmb.sfx_walking || tmp_cmb.sfx_standing
9748
5/10
✓ Branch 0 taken 96996 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96996 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 96996 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 96996 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 96996 times.
✗ Branch 9 not taken.
96996 || tmp_cmb.spr_appear || tmp_cmb.spr_disappear || tmp_cmb.spr_walking || tmp_cmb.spr_standing || tmp_cmb.sfx_tap)
9749 131132 combo_has_flags |= CHAS_GENERAL;
9750
9751
2/2
✓ Branch 0 taken 97004 times.
✓ Branch 1 taken 34128 times.
131132 if(!p_putc(combo_has_flags,f))
9752 {
9753 34128 return 50;
9754 }
9755
2/2
✓ Branch 0 taken 44820 times.
✓ Branch 1 taken 52184 times.
97004 if(!combo_has_flags) return 0; //Valid, done reading
9756 //Write the combo
9757
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44820 times.
44820 if(combo_has_flags&CHAS_BASIC)
9758 {
9759
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_iputl(tmp_cmb.o_tile,f))
9760 return 6;
9761
9762
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.flip,f))
9763 return 7;
9764
9765
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.walk,f))
9766 return 8;
9767
9768
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.type,f))
9769 return 9;
9770
9771
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.flag,f))
9772 return 15;
9773
9774
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(!p_putc(tmp_cmb.csets,f))
9775 return 10;
9776 44820 }
9777
1/2
✓ Branch 0 taken 44820 times.
✗ Branch 1 not taken.
44820 if(combo_has_flags&CHAS_SCRIPT)
9778 {
9779 p_putcstr(tmp_cmb.label, f);
9780
9781 if(!p_iputw(tmp_cmb.script,f))
9782 return 26;
9783 for ( int32_t q = 0; q < 8; q++ )
9784 if(!p_iputl(tmp_cmb.initd[q],f))
9785 return 27;
9786 }
9787
2/2
✓ Branch 0 taken 27474 times.
✓ Branch 1 taken 17346 times.
44820 if(combo_has_flags&CHAS_ANIM)
9788 {
9789
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.frames,f))
9790 return 11;
9791
9792
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.speed,f))
9793 return 12;
9794
9795
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_iputw(tmp_cmb.nextcombo,f))
9796 return 13;
9797
9798
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.nextcset,f))
9799 return 14;
9800
9801
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.skipanim,f))
9802 return 16;
9803
9804
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.skipanimy,f))
9805 return 18;
9806
9807
1/2
✓ Branch 0 taken 17346 times.
✗ Branch 1 not taken.
17346 if(!p_putc(tmp_cmb.animflags,f))
9808 return 19;
9809 17346 }
9810
2/2
✓ Branch 0 taken 42552 times.
✓ Branch 1 taken 2268 times.
44820 if(combo_has_flags&CHAS_ATTRIB)
9811 {
9812
2/2
✓ Branch 0 taken 9072 times.
✓ Branch 1 taken 2268 times.
11340 for ( int32_t q = 0; q < 4; q++ )
9813
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9072 times.
9072 if(!p_iputl(tmp_cmb.attributes[q],f))
9814 return 20;
9815
2/2
✓ Branch 0 taken 18144 times.
✓ Branch 1 taken 2268 times.
20412 for ( int32_t q = 0; q < 8; q++ )
9816
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18144 times.
18144 if(!p_putc(tmp_cmb.attribytes[q],f))
9817 return 25;
9818
2/2
✓ Branch 0 taken 18144 times.
✓ Branch 1 taken 2268 times.
20412 for ( int32_t q = 0; q < 8; q++ ) //I also added attrishorts -Dimi
9819
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18144 times.
18144 if(!p_iputw(tmp_cmb.attrishorts[q],f))
9820 return 32;
9821 2268 }
9822
2/2
✓ Branch 0 taken 44636 times.
✓ Branch 1 taken 184 times.
44820 if(combo_has_flags&CHAS_FLAG)
9823 {
9824
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 184 times.
184 if(!p_iputl(tmp_cmb.usrflags,f))
9825 return 21;
9826
1/2
✓ Branch 0 taken 184 times.
✗ Branch 1 not taken.
184 if(!p_iputw(tmp_cmb.genflags,f))
9827 return 33;
9828 184 }
9829
2/2
✓ Branch 0 taken 44652 times.
✓ Branch 1 taken 168 times.
44820 if(combo_has_flags&CHAS_TRIG)
9830 {
9831
2/2
✓ Branch 0 taken 1008 times.
✓ Branch 1 taken 168 times.
1176 for ( int32_t q = 0; q < 6; q++ )
9832
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1008 times.
1008 if(!p_iputl(tmp_cmb.triggerflags[q],f))
9833 return 22;
9834
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.triggerlevel,f))
9835 return 23;
9836
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.triggerbtn,f))
9837 return 34;
9838
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.triggeritem,f))
9839 return 35;
9840
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigtimer,f))
9841 return 36;
9842
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigsfx,f))
9843 return 37;
9844
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.trigchange,f))
9845 return 38;
9846
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168 times.
168 if(!p_iputw(tmp_cmb.trigprox,f))
9847 return 39;
9848
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigctr,f))
9849 return 40;
9850
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.trigctramnt,f))
9851 return 41;
9852
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.triglbeam,f))
9853 return 42;
9854
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigcschange,f))
9855 return 43;
9856
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.spawnitem,f))
9857 return 44;
9858
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.spawnenemy,f))
9859 return 45;
9860
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.exstate,f))
9861 return 46;
9862
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.spawnip,f))
9863 return 47;
9864
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigcopycat,f))
9865 return 48;
9866
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trigcooldown,f))
9867 return 49;
9868
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.prompt_cid,f))
9869 return 50;
9870
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.prompt_cs,f))
9871 return 51;
9872
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.prompt_x,f))
9873 return 52;
9874
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.prompt_y,f))
9875 return 53;
9876
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_lstate,f))
9877 return 69;
9878
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_gstate,f))
9879 return 70;
9880
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputl(tmp_cmb.trig_statetime,f))
9881 return 71;
9882
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_genscr,f))
9883 return 72;
9884
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_group,f))
9885 return 76;
9886
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_group_val,f))
9887 return 77;
9888
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.exdoor_dir,f))
9889 return 89;
9890
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.exdoor_ind,f))
9891 return 90;
9892
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_levelitems,f))
9893 return 91;
9894
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trigdmlevel,f))
9895 return 92;
9896
2/2
✓ Branch 0 taken 504 times.
✓ Branch 1 taken 168 times.
672 for(int q = 0; q < 3; ++q)
9897
1/2
✓ Branch 0 taken 504 times.
✗ Branch 1 not taken.
504 if(!p_putc(tmp_cmb.trigtint[q],f))
9898 return 93;
9899
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.triglvlpalette,f))
9900 return 94;
9901
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trigbosspalette,f))
9902 return 95;
9903
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trigquaketime,f))
9904 return 96;
9905
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trigwavytime,f))
9906 return 97;
9907
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_swjinxtime,f))
9908 return 98;
9909
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_itmjinxtime,f))
9910 return 99;
9911
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_stuntime,f))
9912 return 100;
9913
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_iputw(tmp_cmb.trig_bunnytime,f))
9914 return 101;
9915
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if(!p_putc(tmp_cmb.trig_pushtime,f))
9916 return 102;
9917 168 }
9918
2/2
✓ Branch 0 taken 44812 times.
✓ Branch 1 taken 8 times.
44820 if(combo_has_flags&CHAS_LIFT)
9919 {
9920
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_iputw(tmp_cmb.liftcmb,f))
9921 return 54;
9922
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftcs,f))
9923 return 55;
9924
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_iputw(tmp_cmb.liftundercmb,f))
9925 return 56;
9926
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftundercs,f))
9927 return 57;
9928
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftdmg,f))
9929 return 58;
9930
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftlvl,f))
9931 return 59;
9932
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftitm,f))
9933 return 60;
9934
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftflags,f))
9935 return 61;
9936
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftgfx,f))
9937 return 62;
9938
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftsprite,f))
9939 return 63;
9940
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftsfx,f))
9941 return 64;
9942
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_iputw(tmp_cmb.liftbreaksprite,f))
9943 return 65;
9944
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.liftbreaksfx,f))
9945 return 66;
9946
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.lifthei,f))
9947 return 67;
9948
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.lifttime,f))
9949 return 68;
9950
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.lift_parent_item,f))
9951 return 78;
9952 8 }
9953
2/2
✓ Branch 0 taken 44812 times.
✓ Branch 1 taken 8 times.
44820 if(combo_has_flags&CHAS_GENERAL)
9954 {
9955
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.speed_mult,f))
9956 return 73;
9957
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.speed_div,f))
9958 return 74;
9959
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_iputzf(tmp_cmb.speed_add,f))
9960 return 75;
9961
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_appear,f))
9962 return 79;
9963
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_disappear,f))
9964 return 80;
9965
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_loop,f))
9966 return 81;
9967
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_walking,f))
9968 return 82;
9969
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_standing,f))
9970 return 83;
9971
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.spr_appear,f))
9972 return 84;
9973
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.spr_disappear,f))
9974 return 85;
9975
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.spr_walking,f))
9976 return 86;
9977
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.spr_standing,f))
9978 return 87;
9979
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!p_putc(tmp_cmb.sfx_tap,f))
9980 return 88;
9981 8 }
9982 44820 return 0;
9983 131132 }
9984
9985 6 int32_t writecombos(PACKFILE *f, word version, word build, word start_combo, word max_combos)
9986 {
9987 //these are here to bypass compiler warnings about unused arguments
9988 6 version=version;
9989 6 build=build;
9990
9991 word combos_used;
9992 6 dword section_id=ID_COMBOS;
9993 6 dword section_version=V_COMBOS;
9994 6 dword section_cversion=CV_COMBOS;
9995 // dword section_size=0;
9996 6 combos_used = count_combos()-start_combo;
9997
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 combos_used = zc_min(combos_used, max_combos);
9998
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 combos_used = zc_min(combos_used, MAXCOMBOS);
9999 6 dword section_size = 0;
10000
10001 //section id
10002
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10003 {
10004 new_return(1);
10005 }
10006
10007 //section version info
10008
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10009 {
10010 new_return(2);
10011 }
10012
10013
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
10014 {
10015 new_return(3);
10016 }
10017
10018
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10019 {
10020 12 fake_pack_writing=(writecycle==0);
10021
10022 //section size
10023
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10024 {
10025 new_return(4);
10026 }
10027
10028 12 writesize=0;
10029
10030 //finally... section data
10031 12 combos_used=count_combos()-start_combo;
10032
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 combos_used=zc_min(combos_used, max_combos);
10033
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 combos_used=zc_min(combos_used, MAXCOMBOS);
10034
10035
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(combos_used,f))
10036 {
10037 new_return(5);
10038 }
10039
10040 12 size_t end_combo = start_combo+combos_used;
10041
2/2
✓ Branch 0 taken 97004 times.
✓ Branch 1 taken 12 times.
97016 for(size_t q = start_combo; q < end_combo; ++q)
10042 {
10043 97004 auto ret = writecombo_loop(f, section_version, combobuf[q]);
10044
1/4
✓ Branch 0 taken 97004 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
97004 if(ret) new_return(ret);
10045 97004 }
10046
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10047 {
10048 6 section_size=writesize;
10049 6 }
10050 12 }
10051
10052
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10053 {
10054 char ebuf[80];
10055 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10056 jwin_alert("Error: writecombos()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10057 }
10058
10059 6 new_return(0);
10060 6 }
10061
10062 6 int32_t writecomboaliases(PACKFILE *f, word version, word build)
10063 {
10064 //these are here to bypass compiler warnings about unused arguments
10065 6 version=version;
10066 6 build=build;
10067
10068 6 dword section_id=ID_COMBOALIASES;
10069 6 dword section_version=V_COMBOALIASES;
10070 6 dword section_cversion=CV_COMBOALIASES;
10071 6 dword section_size=0;
10072
10073 //section id
10074
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10075 {
10076 new_return(1);
10077 }
10078
10079 //section version info
10080
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10081 {
10082 new_return(2);
10083 }
10084
10085
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10086 {
10087 new_return(3);
10088 }
10089
10090
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10091 {
10092 12 fake_pack_writing=(writecycle==0);
10093
10094 //section size
10095
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10096 {
10097 new_return(4);
10098 }
10099
10100 12 writesize=0;
10101
10102 //finally... section data
10103
2/2
✓ Branch 0 taken 98304 times.
✓ Branch 1 taken 12 times.
98316 for(int32_t j=0; j<MAXCOMBOALIASES; j++)
10104 {
10105
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_iputw(combo_aliases[j].combo,f))
10106 {
10107 new_return(5);
10108 }
10109
10110
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_putc(combo_aliases[j].cset,f))
10111 {
10112 new_return(6);
10113 }
10114
10115 98304 int32_t count = ((combo_aliases[j].width+1)*(combo_aliases[j].height+1))*(comboa_lmasktotal(combo_aliases[j].layermask)+1);
10116
10117
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_putc(combo_aliases[j].width,f))
10118 {
10119 new_return(7);
10120 }
10121
10122
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_putc(combo_aliases[j].height,f))
10123 {
10124 new_return(8);
10125 }
10126
10127
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if(!p_putc(combo_aliases[j].layermask,f))
10128 {
10129 new_return(9);
10130 }
10131
10132
2/2
✓ Branch 0 taken 99792 times.
✓ Branch 1 taken 98304 times.
198096 for(int32_t k=0; k<count; k++)
10133 {
10134
1/2
✓ Branch 0 taken 99792 times.
✗ Branch 1 not taken.
99792 if(!p_iputw(combo_aliases[j].combos[k],f))
10135 {
10136 new_return(10);
10137 }
10138 99792 }
10139
10140
2/2
✓ Branch 0 taken 99792 times.
✓ Branch 1 taken 98304 times.
198096 for(int32_t k=0; k<count; k++)
10141 {
10142
1/2
✓ Branch 0 taken 99792 times.
✗ Branch 1 not taken.
99792 if(!p_putc(combo_aliases[j].csets[k],f))
10143 {
10144 new_return(11);
10145 }
10146 99792 }
10147 98304 }
10148
10149 //Combo pools!
10150 int16_t num_cpools;
10151
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 98300 times.
98310 for(num_cpools = MAXCOMBOPOOLS-1; num_cpools >= 0; --num_cpools)
10152 {
10153
2/2
✓ Branch 0 taken 98298 times.
✓ Branch 1 taken 2 times.
98300 if(combo_pools[num_cpools].valid()) //found a used pool
10154 {
10155 2 ++num_cpools;
10156 2 break;
10157 }
10158 98298 }
10159
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10 times.
12 if(num_cpools < 0) num_cpools = 0;
10160
10161
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(num_cpools,f))
10162 {
10163 new_return(12);
10164 }
10165
10166
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(auto cp = 0; cp < num_cpools; ++cp)
10167 {
10168 6 combo_pool const& pool = combo_pools[cp];
10169 6 int32_t num_combos = pool.combos.size();
10170
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(num_combos,f))
10171 {
10172 new_return(13);
10173 }
10174
10175
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 6 times.
32 for(auto q = 0; q < num_combos; ++q)
10176 {
10177 26 cpool_entry const& entry = pool.combos.at(q);
10178
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl(entry.cid,f))
10179 {
10180 new_return(14);
10181 }
10182
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_putc(entry.cset,f))
10183 {
10184 new_return(15);
10185 }
10186
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputw(entry.quant,f))
10187 {
10188 new_return(16);
10189 }
10190 26 }
10191 6 }
10192
10193 //Autocombos!
10194 int16_t num_cautos;
10195
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 98304 times.
98316 for (num_cautos = MAXAUTOCOMBOS - 1; num_cautos >= 0; --num_cautos)
10196 {
10197
1/2
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
98304 if (combo_autos[num_cautos].valid()) //found a used autocombo
10198 {
10199 ++num_cautos;
10200 break;
10201 }
10202 98304 }
10203
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (num_cautos < 0) num_cautos = 0;
10204
10205
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_iputw(num_cautos, f))
10206 {
10207 new_return(17);
10208 }
10209
10210
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 for (auto ca = 0; ca < num_cautos; ++ca)
10211 {
10212 combo_auto const& cauto = combo_autos[ca];
10213 if (!p_putc(cauto.getType(), f))
10214 {
10215 new_return(18);
10216 }
10217 if (!p_iputl(cauto.getIconDisplay(), f))
10218 {
10219 new_return(19);
10220 }
10221 if (!p_iputl(cauto.getEraseCombo(), f))
10222 {
10223 new_return(20);
10224 }
10225 if (!p_putc(cauto.getFlags(), f))
10226 {
10227 new_return(21);
10228 }
10229 if (!p_putc(cauto.getArg(), f))
10230 {
10231 new_return(22);
10232 }
10233 int32_t num_combos = cauto.combos.size();
10234 if (!p_iputl(num_combos, f))
10235 {
10236 new_return(23);
10237 }
10238
10239 for (auto q = 0; q < num_combos; ++q)
10240 {
10241 autocombo_entry const& entry = cauto.combos.at(q);
10242 if (!p_putc(entry.ctype, f))
10243 {
10244 new_return(24);
10245 }
10246 if (!p_iputl(entry.cid, f))
10247 {
10248 new_return(25);
10249 }
10250 }
10251 }
10252
10253
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10254 {
10255 6 section_size=writesize;
10256 6 }
10257 12 }
10258
10259
10260
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10261 {
10262 char ebuf[80];
10263 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10264 jwin_alert("Error: writecomboaliases()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10265 }
10266
10267 6 new_return(0);
10268 }
10269
10270 6 int32_t writecolordata(PACKFILE *f, word version, word build, word start_cset, word max_csets)
10271 {
10272 //these are here to bypass compiler warnings about unused arguments
10273 6 version=version;
10274 6 build=build;
10275 6 start_cset=start_cset;
10276 6 max_csets=max_csets;
10277
10278 6 dword section_id=ID_CSETS;
10279 6 dword section_version=V_CSETS;
10280 6 dword section_cversion=CV_CSETS;
10281 6 int32_t palcycles = count_palcycles(&QMisc);
10282 // int32_t palcyccount = count_palcycles(&QMisc);
10283 6 dword section_size = 0;
10284
10285 //section id
10286
10287
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10288 {
10289 new_return(1);
10290 }
10291
10292 //section version info
10293
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10294 {
10295 new_return(2);
10296 }
10297
10298
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10299 {
10300 new_return(3);
10301 }
10302
10303
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10304 {
10305 12 fake_pack_writing=(writecycle==0);
10306
10307 //section size
10308
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10309 {
10310 new_return(4);
10311 }
10312
10313 12 writesize=0;
10314
10315 //finally... section data
10316
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(colordata,psTOTAL255,f))
10317 {
10318 new_return(5);
10319 }
10320
10321
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(palnames,MAXLEVELS*PALNAMESIZE,f))
10322 {
10323 new_return(6);
10324 }
10325
10326
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(palcycles,f))
10327 {
10328 new_return(15);
10329 }
10330
10331
2/2
✓ Branch 0 taken 276 times.
✓ Branch 1 taken 12 times.
288 for(int32_t i=0; i<palcycles; i++)
10332 {
10333
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 276 times.
1104 for(int32_t j=0; j<3; j++)
10334 {
10335
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(QMisc.cycles[i][j].first,f))
10336 {
10337 new_return(16);
10338 }
10339 828 }
10340
10341
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 276 times.
1104 for(int32_t j=0; j<3; j++)
10342 {
10343
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(QMisc.cycles[i][j].count,f))
10344 {
10345 new_return(17);
10346 }
10347 828 }
10348
10349
2/2
✓ Branch 0 taken 828 times.
✓ Branch 1 taken 276 times.
1104 for(int32_t j=0; j<3; j++)
10350 {
10351
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(QMisc.cycles[i][j].speed,f))
10352 {
10353 new_return(18);
10354 }
10355 828 }
10356 276 }
10357
10358
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10359 {
10360 6 section_size=writesize;
10361 6 }
10362 12 }
10363
10364
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10365 {
10366 char ebuf[80];
10367 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10368 jwin_alert("Error: writecolordata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10369 }
10370
10371 6 new_return(0);
10372 }
10373
10374 6 int32_t writestrings(PACKFILE *f, word version, word build, word start_msgstr, word max_msgstrs)
10375 {
10376 //these are here to bypass compiler warnings about unused arguments
10377 6 version=version;
10378 6 build=build;
10379 6 start_msgstr=start_msgstr;
10380 6 max_msgstrs=max_msgstrs;
10381
10382 6 dword section_id=ID_STRINGS;
10383 6 dword section_version=V_STRINGS;
10384 6 dword section_cversion=CV_STRINGS;
10385 6 dword section_size = 0;
10386
10387 //section id
10388
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10389 {
10390 new_return(1);
10391 }
10392
10393 //section version info
10394
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10395 {
10396 new_return(2);
10397 }
10398
10399
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10400 {
10401 new_return(3);
10402 }
10403
10404
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10405 {
10406 12 fake_pack_writing=(writecycle==0);
10407
10408 //section size
10409
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10410 {
10411 new_return(4);
10412 }
10413
10414 12 writesize=0;
10415
10416 //finally... section data
10417
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(msg_count,f))
10418 {
10419 return qe_invalid;
10420 }
10421
10422
2/2
✓ Branch 0 taken 302 times.
✓ Branch 1 taken 12 times.
314 for(int32_t i=0; i<msg_count; i++)
10423 {
10424 302 int32_t sz = MsgStrings[i].s.size();
10425
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(sz > 8192) sz = 8192;
10426
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputl(sz, f))
10427 {
10428 return qe_invalid;
10429 }
10430
10431 302 char const* tmpstr = MsgStrings[i].s.c_str();
10432
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 302 times.
302 if (sz > 0)
10433 {
10434
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if (!pfwrite((void*)tmpstr,sz, f))
10435 {
10436 return qe_invalid;
10437 }
10438 302 }
10439
10440
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].nextstring,f))
10441 {
10442 return qe_invalid;
10443 }
10444
10445
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputl(MsgStrings[i].tile,f))
10446 {
10447 return qe_invalid;
10448 }
10449
10450
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].cset,f))
10451 {
10452 return qe_invalid;
10453 }
10454
10455
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].trans?1:0,f))
10456 {
10457 return qe_invalid;
10458 }
10459
10460
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].font,f))
10461 {
10462 return qe_invalid;
10463 }
10464
10465
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].x,f))
10466 {
10467 return qe_invalid;
10468 }
10469
10470
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].y,f))
10471 {
10472 return qe_invalid;
10473 }
10474
10475
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].w,f))
10476 {
10477 return qe_invalid;
10478 }
10479
10480
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].h,f))
10481 {
10482 return qe_invalid;
10483 }
10484
10485
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].hspace,f))
10486 {
10487 return qe_invalid;
10488 }
10489
10490
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].vspace,f))
10491 {
10492 return qe_invalid;
10493 }
10494
10495
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].stringflags,f))
10496 {
10497 return qe_invalid;
10498 }
10499
10500
2/2
✓ Branch 0 taken 1208 times.
✓ Branch 1 taken 302 times.
1510 for(int32_t q = 0; q < 4; ++q)
10501 {
10502
1/2
✓ Branch 0 taken 1208 times.
✗ Branch 1 not taken.
1208 if(!p_putc(MsgStrings[i].margins[q],f))
10503 {
10504 return qe_invalid;
10505 }
10506 1208 }
10507
10508
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputl(MsgStrings[i].portrait_tile,f))
10509 {
10510 return qe_invalid;
10511 }
10512
10513
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_cset,f))
10514 {
10515 return qe_invalid;
10516 }
10517
10518
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_x,f))
10519 {
10520 return qe_invalid;
10521 }
10522
10523
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_y,f))
10524 {
10525 return qe_invalid;
10526 }
10527
10528
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_tw,f))
10529 {
10530 return qe_invalid;
10531 }
10532
10533
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].portrait_th,f))
10534 {
10535 return qe_invalid;
10536 }
10537
10538
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].shadow_type,f))
10539 {
10540 return qe_invalid;
10541 }
10542
10543
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].shadow_color,f))
10544 {
10545 return qe_invalid;
10546 }
10547
10548
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].drawlayer,f))
10549 {
10550 return qe_invalid;
10551 }
10552
10553
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_putc(MsgStrings[i].sfx,f))
10554 {
10555 return qe_invalid;
10556 }
10557
10558
1/2
✓ Branch 0 taken 302 times.
✗ Branch 1 not taken.
302 if(!p_iputw(MsgStrings[i].listpos,f))
10559 {
10560 return qe_invalid;
10561 }
10562 302 }
10563
10564
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10565 {
10566 6 section_size=writesize;
10567 6 }
10568 12 }
10569
10570
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10571 {
10572 char ebuf[80];
10573 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10574 jwin_alert("Error: writestrings()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10575 }
10576
10577 6 new_return(0);
10578 6 }
10579
10580 int32_t writestrings_text(PACKFILE *f)
10581 {
10582 std::map<int32_t, int32_t> msglistcache;
10583
10584 for(int32_t index = 1; index<msg_count; index++)
10585 {
10586 for(int32_t i=1; i<msg_count; i++)
10587 {
10588 if(MsgStrings[i].listpos==index)
10589 {
10590 msglistcache[index-1]=i;
10591 break;
10592 }
10593 }
10594 }
10595
10596 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10597 {
10598 fake_pack_writing=(writecycle==0);
10599 char ebuf[32];
10600
10601 sprintf(ebuf,"Total strings: %d\n", msg_count-1);
10602
10603 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10604 {
10605 return qe_invalid;
10606 }
10607
10608 for(int32_t i=1; i<msg_count; i++)
10609 {
10610 int32_t str = msglistcache[i-1];
10611
10612 if(!str)
10613 continue;
10614
10615 if(MsgStrings[str].nextstring != 0)
10616 sprintf(ebuf,"\n\n___%d(->%d)___\n", str,MsgStrings[str].nextstring);
10617 else
10618 sprintf(ebuf,"\n\n___%d___\n", str);
10619
10620 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10621 {
10622 return qe_invalid;
10623 }
10624
10625 encode_msg_str(str);
10626
10627 if(!pfwrite(&msgbuf,(int32_t)strlen(msgbuf),f))
10628 {
10629 return qe_invalid;
10630 }
10631 }
10632 }
10633
10634 new_return(0);
10635 }
10636
10637 1 int32_t writestrings_tsv(PACKFILE *f)
10638 {
10639 1 std::stringstream ss;
10640
10641 int32_t str;
10642
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::vector<std::pair<std::string, std::function<std::string(const MsgStr&)>>> fields = {
10643
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "message", [&](auto& msg){
10644 35 encode_msg_str(str);
10645 35 return msgbuf;
10646 }},
10647
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "next", [](auto& msg){ return std::to_string(msg.nextstring); } },
10648
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "tile", [](auto& msg){ return std::to_string(msg.tile); } },
10649
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "cset", [](auto& msg){ return std::to_string(msg.cset); } },
10650
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "trans", [](auto& msg){ return std::to_string(msg.trans); } },
10651
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "font", [](auto& msg){ return std::to_string(msg.font); } },
10652
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "x", [](auto& msg){ return std::to_string(msg.x); } },
10653
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "y", [](auto& msg){ return std::to_string(msg.y); } },
10654
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "w", [](auto& msg){ return std::to_string(msg.w); } },
10655
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "h", [](auto& msg){ return std::to_string(msg.h); } },
10656
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "sfx", [](auto& msg){ return std::to_string(msg.sfx); } },
10657
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "pos", [](auto& msg){ return std::to_string(msg.listpos); } },
10658
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "vspace", [](auto& msg){ return std::to_string(msg.vspace); } },
10659
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "hspace", [](auto& msg){ return std::to_string(msg.hspace); } },
10660
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "flags", [](auto& msg){ return std::to_string(msg.stringflags); } },
10661
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "margin", [](auto& msg){ return fmt::format("{} {} {} {}", msg.margins[0], msg.margins[3], msg.margins[1], msg.margins[2]); } },
10662
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tile", [](auto& msg){ return std::to_string(msg.portrait_tile); } },
10663
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_cset", [](auto& msg){ return std::to_string(msg.portrait_cset); } },
10664
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_x", [](auto& msg){ return std::to_string(msg.portrait_x); } },
10665
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_y", [](auto& msg){ return std::to_string(msg.portrait_y); } },
10666
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tw", [](auto& msg){ return std::to_string(msg.portrait_tw); } },
10667
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_th", [](auto& msg){ return std::to_string(msg.portrait_th); } },
10668
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_type", [](auto& msg){ return std::to_string(msg.shadow_type); } },
10669
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_color", [](auto& msg){ return std::to_string(msg.shadow_color); } },
10670
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "drawlayer", [](auto& msg){ return std::to_string(msg.drawlayer); } },
10671 };
10672
10673
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 for (auto& [name, fn] : fields)
10674 {
10675
2/4
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
50 ss << name;
10676
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1 times.
25 if (name == fields.back().first)
10677 1 break;
10678
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 ss << '\t';
10679 }
10680
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << '\n';
10681
10682 // First entry is a fake string, to help frame the lines. Should be helpful if manually editing these in a text editor or spreadsheet.
10683
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << "|IT'S DANGEROUS TO GO || ALONE! TAKE THIS. ||LOREM IPSUM LOREM IPSU|\n";
10684
10685
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 35 times.
36 for(int32_t i=1; i<msg_count; i++)
10686 {
10687 35 str = i;
10688 35 auto& msg = MsgStrings[str];
10689
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
1750 for (auto& [name, fn] : fields)
10690 {
10691
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 std::string text = fn(msg);
10692
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 ss << text;
10693
2/2
✓ Branch 0 taken 840 times.
✓ Branch 1 taken 35 times.
875 if (name == fields.back().first)
10694 35 break;
10695
1/2
✓ Branch 0 taken 840 times.
✗ Branch 1 not taken.
840 ss << '\t';
10696
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 840 times.
875 }
10697
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 ss << '\n';
10698 35 }
10699
10700
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::string text = ss.str();
10701
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (!pack_fwrite(text.c_str(), text.size(), f))
10702 {
10703 return qe_invalid;
10704 }
10705
10706 1 new_return(0);
10707 1 }
10708
10709 void parse_strings_tsv(std::string tsv)
10710 {
10711 std::string parse_msg_str(std::string const& s);
10712 std::map<std::string, std::function<void(MsgStr&, const std::string&)>> fields = {
10713 { "message", [](auto& msg, auto& text){ msg.s = parse_msg_str(text); } },
10714 { "next", [](auto& msg, auto& text){ msg.nextstring = std::stoi(text); } },
10715 { "tile", [](auto& msg, auto& text){ msg.tile = std::stoi(text); } },
10716 { "cset", [](auto& msg, auto& text){ msg.cset = std::stoi(text); } },
10717 { "trans", [](auto& msg, auto& text){ msg.trans = std::stoi(text); } },
10718 { "font", [](auto& msg, auto& text){ msg.font = std::stoi(text); } },
10719 { "x", [](auto& msg, auto& text){ msg.x = std::stoi(text); } },
10720 { "y", [](auto& msg, auto& text){ msg.y = std::stoi(text); } },
10721 { "w", [](auto& msg, auto& text){ msg.w = std::stoi(text); } },
10722 { "h", [](auto& msg, auto& text){ msg.h = std::stoi(text); } },
10723 { "sfx", [](auto& msg, auto& text){ msg.sfx = std::stoi(text); } },
10724 { "pos", [](auto& msg, auto& text){ msg.listpos = std::stoi(text); } },
10725 { "vspace", [](auto& msg, auto& text){ msg.vspace = std::stoi(text); } },
10726 { "hspace", [](auto& msg, auto& text){ msg.hspace = std::stoi(text); } },
10727 { "flags", [](auto& msg, auto& text){ msg.stringflags = std::stoi(text); } },
10728 { "margin", [&](auto& msg, auto& text){
10729 std::vector<std::string> strs;
10730 util::split(text, strs, ' ');
10731 if (strs.size() != 4)
10732 throw std::runtime_error("margin field must have 4 components");
10733 msg.margins[0] = std::stoi(strs[0]);
10734 msg.margins[1] = std::stoi(strs[1]);
10735 msg.margins[2] = std::stoi(strs[2]);
10736 msg.margins[3] = std::stoi(strs[3]);
10737 } },
10738 { "portrait_tile", [](auto& msg, auto& text){ msg.portrait_tile = std::stoi(text); } },
10739 { "portrait_cset", [](auto& msg, auto& text){ msg.portrait_cset = std::stoi(text); } },
10740 { "portrait_x", [](auto& msg, auto& text){ msg.portrait_x = std::stoi(text); } },
10741 { "portrait_y", [](auto& msg, auto& text){ msg.portrait_y = std::stoi(text); } },
10742 { "portrait_tw", [](auto& msg, auto& text){ msg.portrait_tw = std::stoi(text); } },
10743 { "portrait_th", [](auto& msg, auto& text){ msg.portrait_th = std::stoi(text); } },
10744 { "shadow_type", [](auto& msg, auto& text){ msg.shadow_type = std::stoi(text); } },
10745 { "shadow_color", [](auto& msg, auto& text){ msg.shadow_color = std::stoi(text); } },
10746 { "drawlayer", [](auto& msg, auto& text){ msg.drawlayer = std::stoi(text); } },
10747 };
10748
10749 std::vector<std::string> rows;
10750 util::split(tsv, rows, '\n');
10751 if (rows.size())
10752 {
10753 std::string last = rows.back();
10754 util::trimstr(last);
10755 if (last.empty())
10756 rows.pop_back();
10757 }
10758 if (rows.size() <= 1)
10759 throw std::runtime_error("missing header row");
10760
10761 std::vector<std::string> columns;
10762 util::split(rows[0], columns, '\t');
10763 for (auto name : columns)
10764 {
10765 if (!fields.contains(name))
10766 throw std::runtime_error(fmt::format("invalid field: {}", name));
10767 }
10768
10769 int start_index = 1;
10770 if (rows[start_index].find("||LOREM IPSUM") != std::string::npos)
10771 start_index += 1;
10772
10773 int num_strings = rows.size() - start_index + 1;
10774 if (num_strings > MAXMSGS-1)
10775 throw std::runtime_error(fmt::format("too many strings, max is {}", MAXMSGS-1));
10776
10777 std::vector<MsgStr> msgs;
10778 msgs.reserve(num_strings);
10779 for (int i = start_index; i < rows.size(); i++)
10780 {
10781 std::vector<std::string> strs;
10782 util::split(rows[i], strs, '\t');
10783 if (strs.size() != columns.size())
10784 throw std::runtime_error(fmt::format("row {} has {} fields, expected {}", i, strs.size(), columns.size()));
10785
10786 int j = 0;
10787 auto& msg = msgs.emplace_back();
10788 for (auto& name : columns)
10789 {
10790 auto& fn = fields[name];
10791 try
10792 {
10793 fn(msg, strs[j++]);
10794 }
10795 catch (std::exception& ex)
10796 {
10797 throw std::runtime_error(fmt::format("error parsing row {} field {}: {}", i, name, ex.what()));
10798 }
10799 }
10800 }
10801
10802 init_msgstrings(0, msgs.size());
10803 for (int i = 0; i < msgs.size(); i++)
10804 MsgStrings[i + 1] = msgs[i];
10805 msg_count = msgs.size();
10806 msglistcache.clear();
10807 }
10808
10809 bool isblanktile(tiledata *buf, int32_t i);
10810 6 int32_t writetiles(PACKFILE *f, word version, word build, int32_t start_tile, int32_t max_tiles)
10811 {
10812 //these are here to bypass compiler warnings about unused arguments
10813 6 version=version;
10814 6 build=build;
10815
10816 int32_t tiles_used;
10817 6 dword section_id=ID_TILES;
10818 6 dword section_version=V_TILES;
10819 6 dword section_cversion=CV_TILES;
10820 6 al_trace("Counting tiles used\n");
10821 6 tiles_used = count_tiles(newtilebuf)-start_tile;
10822
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 tiles_used = zc_min(tiles_used, max_tiles);
10823
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 tiles_used = zc_min(tiles_used, NEWMAXTILES);
10824 6 al_trace("writetiles counted %dtiles used.\n",tiles_used);
10825 6 dword section_size = 0;
10826
10827 //section id
10828
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10829 {
10830 new_return(1);
10831 }
10832
10833 //section version info
10834
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10835 {
10836 new_return(2);
10837 }
10838
10839
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10840 {
10841 new_return(3);
10842 }
10843
10844
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10845 {
10846 12 fake_pack_writing=(writecycle==0);
10847
10848 //section size
10849
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10850 {
10851 new_return(4);
10852 }
10853
10854 12 writesize=0;
10855
10856 //finally... section data
10857 12 tiles_used=count_tiles(newtilebuf)-start_tile;
10858
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 tiles_used=zc_min(tiles_used, max_tiles);
10859
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 tiles_used=zc_min(tiles_used, NEWMAXTILES);
10860
10861
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(tiles_used,f))
10862 {
10863 new_return(5);
10864 }
10865
10866
2/2
✓ Branch 0 taken 448054 times.
✓ Branch 1 taken 12 times.
448066 for(int32_t i=0; i<tiles_used; ++i)
10867 {
10868
2/2
✓ Branch 0 taken 238750 times.
✓ Branch 1 taken 209304 times.
448054 if(isblanktile(newtilebuf, start_tile+i))
10869 {
10870
1/2
✓ Branch 0 taken 238750 times.
✗ Branch 1 not taken.
238750 if(!p_putc(0,f))
10871 new_return(8);
10872 238750 }
10873 else
10874 {
10875 209304 int format = newtilebuf[start_tile+i].format;
10876
1/2
✓ Branch 0 taken 209304 times.
✗ Branch 1 not taken.
209304 if(!p_putc(format,f))
10877 {
10878 new_return(6);
10879 }
10880
10881
2/2
✓ Branch 0 taken 207706 times.
✓ Branch 1 taken 1598 times.
209304 if (format == tf4Bit)
10882 {
10883 byte temp_tile[128];
10884 207706 byte *di = temp_tile;
10885 207706 byte *src = newtilebuf[start_tile+i].data;
10886
2/2
✓ Branch 0 taken 26586368 times.
✓ Branch 1 taken 207706 times.
26794074 for (int32_t si=0; si<256; si+=2)
10887 {
10888 26586368 *di = (src[si]&15) + ((src[si+1]&15) << 4);
10889 26586368 ++di;
10890 26586368 }
10891
1/2
✓ Branch 0 taken 207706 times.
✗ Branch 1 not taken.
207706 if (!pfwrite(temp_tile,128,f))
10892 {
10893 new_return(7);
10894 }
10895 207706 }
10896
1/2
✓ Branch 0 taken 1598 times.
✗ Branch 1 not taken.
1598 else if (!pfwrite(newtilebuf[start_tile+i].data,tilesize(format),f))
10897 {
10898 new_return(7);
10899 }
10900 }
10901 448054 }
10902
10903
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
10904 {
10905 6 section_size=writesize;
10906 6 }
10907 12 }
10908
10909
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
10910 {
10911 char ebuf[80];
10912 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10913 jwin_alert("Error: writetiles()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10914 }
10915
10916 6 new_return(0);
10917 }
10918
10919 /* MIDI Format
10920 section_id LONG
10921 section_version WORD
10922 section_cversion WORD
10923 section_size LONG
10924 midi_flags 32 Byte ? BITFIELD[252]
10925
10926 [
10927 title 36
10928 start 4
10929 loop_start 4
10930 loop_end 4
10931 loop 2
10932 volume 2
10933 midi *
10934 ]
10935
10936 */
10937
10938 6 int32_t writemidis(PACKFILE *f)
10939 {
10940 6 dword section_id=ID_MIDIS;
10941 6 dword section_version=V_MIDIS;
10942 6 dword section_cversion=CV_MIDIS;
10943 6 dword section_size = 0;
10944
10945 //section id
10946
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
10947 {
10948 new_return(1);
10949 }
10950
10951 //section version info
10952
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
10953 {
10954 new_return(2);
10955 }
10956
10957
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
10958 {
10959 new_return(3);
10960 }
10961
10962
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10963 {
10964 12 fake_pack_writing=(writecycle==0);
10965
10966 //section size
10967
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
10968 {
10969 new_return(4);
10970 }
10971
10972 12 writesize=0;
10973
10974 //finally... section data
10975
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(midi_flags,sizeof(midi_flags),f))
10976 {
10977 new_return(5);
10978 }
10979
10980
2/2
✓ Branch 0 taken 3024 times.
✓ Branch 1 taken 12 times.
3036 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
10981 {
10982
2/2
✓ Branch 0 taken 2964 times.
✓ Branch 1 taken 60 times.
3024 if(get_bit(midi_flags,i))
10983 {
10984
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!pfwrite(&customtunes[i].title,sizeof(customtunes[0].title)-1,f))
10985 {
10986 new_return(6);
10987 }
10988
10989
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputl(customtunes[i].start,f))
10990 {
10991 new_return(7);
10992 }
10993
10994
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputl(customtunes[i].loop_start,f))
10995 {
10996 new_return(8);
10997 }
10998
10999
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputl(customtunes[i].loop_end,f))
11000 {
11001 new_return(9);
11002 }
11003
11004
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputw(customtunes[i].loop,f))
11005 {
11006 new_return(10);
11007 }
11008
11009
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!p_iputw(customtunes[i].volume,f))
11010 {
11011 new_return(11);
11012 }
11013
11014
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!pfwrite(&customtunes[i].flags, sizeof(customtunes[i].flags),f))
11015 {
11016 new_return(12);
11017 }
11018
11019
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!pfwrite(&customtunes[i].format, sizeof(customtunes[i].format),f))
11020 {
11021 new_return(13);
11022 }
11023
11024
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 switch(customtunes[i].format)
11025 {
11026 case MFORMAT_MIDI:
11027
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(!write_midi((MIDI*) customtunes[i].data,f)) new_return(14);
11028
11029 60 break;
11030
11031 default:
11032 new_return(15);
11033 break;
11034 }
11035 60 }
11036 3024 }
11037
11038
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
11039 {
11040 6 section_size=writesize;
11041 6 }
11042 12 }
11043
11044
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
11045 {
11046 char ebuf[80];
11047 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
11048 jwin_alert("Error: writemidis()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
11049 }
11050
11051 6 new_return(0);
11052 }
11053
11054 6 int32_t writecheats(PACKFILE *f, zquestheader *Header)
11055 {
11056 6 dword section_id=ID_CHEATS;
11057 6 dword section_version=V_CHEATS;
11058 6 dword section_cversion=CV_CHEATS;
11059 6 dword section_size = 0;
11060
11061 //section id
11062
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
11063 {
11064 new_return(1);
11065 }
11066
11067 //section version info
11068
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
11069 {
11070 new_return(2);
11071 }
11072
11073
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
11074 {
11075 new_return(3);
11076 }
11077
11078
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11079 {
11080 12 fake_pack_writing=(writecycle==0);
11081
11082 //section size
11083
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
11084 {
11085 new_return(4);
11086 }
11087
11088 12 writesize=0;
11089
11090 //finally... section data
11091
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(Header->data_flags[ZQ_CHEATS2],f))
11092 {
11093 new_return(5);
11094 }
11095
11096
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(Header->data_flags[ZQ_CHEATS2])
11097 {
11098
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zcheats.flags,f))
11099 {
11100 new_return(6);
11101 }
11102
11103
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!pfwrite(&zcheats.codes, sizeof(zcheats.codes), f))
11104 {
11105 new_return(7);
11106 }
11107 12 }
11108
11109
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
11110 {
11111 6 section_size=writesize;
11112 6 }
11113 12 }
11114
11115
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
11116 {
11117 char ebuf[80];
11118 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
11119 jwin_alert("Error: writecheats()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
11120 }
11121
11122 6 new_return(0);
11123 }
11124
11125 6 int32_t writeguys(PACKFILE *f, zquestheader *Header)
11126 {
11127 //these are here to bypass compiler warnings about unused arguments
11128 6 Header=Header;
11129
11130 6 dword section_id=ID_GUYS;
11131 6 dword section_version=V_GUYS;
11132 6 dword section_cversion=CV_GUYS;
11133 6 dword section_size=0;
11134
11135 //section id
11136
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
11137 {
11138 new_return(1);
11139 }
11140
11141 //section version info
11142
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
11143 {
11144 new_return(2);
11145 }
11146
11147
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
11148 {
11149 new_return(3);
11150 }
11151
11152
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11153 {
11154 12 fake_pack_writing=(writecycle==0);
11155
11156 //section size
11157
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
11158 {
11159 new_return(4);
11160 }
11161
11162 12 writesize=0;
11163
11164 //finally... section data
11165
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<MAXGUYS; i++)
11166 {
11167
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!pfwrite((char *)guy_string[i], 64, f))
11168 {
11169 new_return(5);
11170 }
11171 6144 }
11172
11173
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6144 times.
6156 for(int32_t i=0; i<MAXGUYS; i++)
11174 {
11175
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].flags,f))
11176 {
11177 new_return(6);
11178 }
11179
11180
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].flags2,f))
11181 {
11182 new_return(7);
11183 }
11184
11185
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].tile,f))
11186 {
11187 new_return(8);
11188 }
11189
11190
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].width,f))
11191 {
11192 new_return(9);
11193 }
11194
11195
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].height,f))
11196 {
11197 new_return(10);
11198 }
11199
11200
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].s_tile,f))
11201 {
11202 new_return(11);
11203 }
11204
11205
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].s_width,f))
11206 {
11207 new_return(12);
11208 }
11209
11210
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].s_height,f))
11211 {
11212 new_return(13);
11213 }
11214
11215
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].e_tile,f))
11216 {
11217 new_return(14);
11218 }
11219
11220
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].e_width,f))
11221 {
11222 new_return(15);
11223 }
11224
11225
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].e_height,f))
11226 {
11227 new_return(16);
11228 }
11229
11230
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].hp,f))
11231 {
11232 new_return(17);
11233 }
11234
11235
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].family,f))
11236 {
11237 new_return(18);
11238 }
11239
11240
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].cset,f))
11241 {
11242 new_return(19);
11243 }
11244
11245
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].anim,f))
11246 {
11247 new_return(20);
11248 }
11249
11250
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].e_anim,f))
11251 {
11252 new_return(21);
11253 }
11254
11255
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].frate,f))
11256 {
11257 new_return(22);
11258 }
11259
11260
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].e_frate,f))
11261 {
11262 new_return(23);
11263 }
11264
11265
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].dp,f))
11266 {
11267 new_return(24);
11268 }
11269
11270
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].wdp,f))
11271 {
11272 new_return(25);
11273 }
11274
11275
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].weapon,f))
11276 {
11277 new_return(26);
11278 }
11279
11280
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].rate,f))
11281 {
11282 new_return(27);
11283 }
11284
11285
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].hrate,f))
11286 {
11287 new_return(28);
11288 }
11289
11290
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].step,f))
11291 {
11292 new_return(29);
11293 }
11294
11295
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].homing,f))
11296 {
11297 new_return(30);
11298 }
11299
11300
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].grumble,f))
11301 {
11302 new_return(31);
11303 }
11304
11305
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].item_set,f))
11306 {
11307 new_return(32);
11308 }
11309
11310
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc1,f))
11311 {
11312 new_return(33);
11313 }
11314
11315
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc2,f))
11316 {
11317 new_return(34);
11318 }
11319
11320
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc3,f))
11321 {
11322 new_return(35);
11323 }
11324
11325
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc4,f))
11326 {
11327 new_return(36);
11328 }
11329
11330
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc5,f))
11331 {
11332 new_return(37);
11333 }
11334
11335
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc6,f))
11336 {
11337 new_return(38);
11338 }
11339
11340
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc7,f))
11341 {
11342 new_return(39);
11343 }
11344
11345
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc8,f))
11346 {
11347 new_return(40);
11348 }
11349
11350
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc9,f))
11351 {
11352 new_return(41);
11353 }
11354
11355
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc10,f))
11356 {
11357 new_return(42);
11358 }
11359
11360
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].bgsfx,f))
11361 {
11362 new_return(43);
11363 }
11364
11365
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].bosspal,f))
11366 {
11367 new_return(44);
11368 }
11369
11370
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].extend,f))
11371 {
11372 new_return(45);
11373 }
11374
11375
2/2
✓ Branch 0 taken 116736 times.
✓ Branch 1 taken 6144 times.
122880 for(int32_t j=0; j < edefLAST; j++)
11376 {
11377
1/2
✓ Branch 0 taken 116736 times.
✗ Branch 1 not taken.
116736 if(!p_putc(guysbuf[i].defense[j],f))
11378 {
11379 new_return(46);
11380 }
11381 116736 }
11382
11383
4/6
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4096 times.
✓ Branch 3 taken 2048 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4096 times.
6144 if ( FFCore.getQuestHeaderInfo(vZelda) < 0x250 || (( FFCore.getQuestHeaderInfo(vZelda) == 0x250 ) && FFCore.getQuestHeaderInfo(vBuild) < 32 ) )
11384 {
11385 //If no user-set hit sound was in place, and the quest was made in a version before 2.53.0 Gamma 2:
11386 if ( guysbuf[i].hitsfx == 0 ) guysbuf[i].hitsfx = WAV_EHIT; //Fix quests using the wrong hit sound when loading this.
11387 //Force SFX_HIT here.
11388
11389 }
11390
11391
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].hitsfx,f))
11392 {
11393 new_return(47);
11394 }
11395
11396
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].deadsfx,f))
11397 {
11398 new_return(48);
11399 }
11400
11401
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc11,f))
11402 {
11403 new_return(49);
11404 }
11405
11406
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc12,f))
11407 {
11408 new_return(50);
11409 }
11410
11411 //New 2.6 defences
11412
2/2
✓ Branch 0 taken 135168 times.
✓ Branch 1 taken 6144 times.
141312 for(int32_t j=edefLAST; j < edefLAST255; j++)
11413 {
11414
1/2
✓ Branch 0 taken 135168 times.
✗ Branch 1 not taken.
135168 if(!p_putc(guysbuf[i].defense[j],f))
11415 {
11416 new_return(51);
11417 }
11418 135168 }
11419
11420 //tilewidth, tileheight, hitwidth, hitheight, hitzheight, hitxofs, hityofs, hitzofs
11421
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].txsz,f))
11422 {
11423 new_return(52);
11424 }
11425
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].tysz,f))
11426 {
11427 new_return(53);
11428 }
11429
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hxsz,f))
11430 {
11431 new_return(54);
11432 }
11433
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hysz,f))
11434 {
11435 new_return(55);
11436 }
11437
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hzsz,f))
11438 {
11439 new_return(56);
11440 }
11441 // These are not fixed types, but ints, so they are safe to use here.
11442
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hxofs,f))
11443 {
11444 new_return(57);
11445 }
11446
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].hyofs,f))
11447 {
11448 new_return(58);
11449 }
11450
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].xofs,f))
11451 {
11452 new_return(59);
11453 }
11454
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].yofs,f))
11455 {
11456 new_return(60);
11457 }
11458
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].zofs,f))
11459 {
11460 new_return(61);
11461 }
11462
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].wpnsprite,f))
11463 {
11464 new_return(62);
11465 }
11466
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].SIZEflags,f))
11467 {
11468 new_return(63);
11469 }
11470
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].frozentile,f))
11471 {
11472 new_return(64);
11473 }
11474
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].frozencset,f))
11475 {
11476 new_return(65);
11477 }
11478
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].frozenclock,f))
11479 {
11480 new_return(66);
11481 }
11482
11483
2/2
✓ Branch 0 taken 61440 times.
✓ Branch 1 taken 6144 times.
67584 for ( int32_t q = 0; q < 10; q++ )
11484 {
11485
1/2
✓ Branch 0 taken 61440 times.
✗ Branch 1 not taken.
61440 if(!p_iputw(guysbuf[i].frozenmisc[q],f))
11486 {
11487 new_return(67);
11488 }
11489 61440 }
11490
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].firesfx,f))
11491 {
11492 new_return(68);
11493 }
11494 //misc 16->31
11495
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc16,f))
11496 {
11497 new_return(69);
11498 }
11499
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc17,f))
11500 {
11501 new_return(70);
11502 }
11503
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc18,f))
11504 {
11505 new_return(71);
11506 }
11507
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc19,f))
11508 {
11509 new_return(72);
11510 }
11511
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc20,f))
11512 {
11513 new_return(73);
11514 }
11515
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc21,f))
11516 {
11517 new_return(74);
11518 }
11519
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc22,f))
11520 {
11521 new_return(75);
11522 }
11523
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc23,f))
11524 {
11525 new_return(76);
11526 }
11527
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc24,f))
11528 {
11529 new_return(77);
11530 }
11531
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc25,f))
11532 {
11533 new_return(78);
11534 }
11535
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc26,f))
11536 {
11537 new_return(79);
11538 }
11539
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc27,f))
11540 {
11541 new_return(80);
11542 }
11543
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc28,f))
11544 {
11545 new_return(81);
11546 }
11547
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc29,f))
11548 {
11549 new_return(82);
11550 }
11551
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc30,f))
11552 {
11553 new_return(83);
11554 }
11555
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc31,f))
11556 {
11557 new_return(84);
11558 }
11559
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc32,f))
11560 {
11561 new_return(85);
11562 }
11563
2/2
✓ Branch 0 taken 196608 times.
✓ Branch 1 taken 6144 times.
202752 for ( int32_t q = 0; q < 32; q++ )
11564 {
11565
1/2
✓ Branch 0 taken 196608 times.
✗ Branch 1 not taken.
196608 if(!p_iputl(guysbuf[i].movement[q],f))
11566 {
11567 new_return(86);
11568 }
11569 196608 }
11570
2/2
✓ Branch 0 taken 196608 times.
✓ Branch 1 taken 6144 times.
202752 for ( int32_t q = 0; q < 32; q++ )
11571 {
11572
1/2
✓ Branch 0 taken 196608 times.
✗ Branch 1 not taken.
196608 if(!p_iputl(guysbuf[i].new_weapon[q],f))
11573 {
11574 new_return(87);
11575 }
11576 196608 }
11577
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].script,f))
11578 {
11579 new_return(88);
11580 }
11581
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
11582 {
11583
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(guysbuf[i].initD[q],f))
11584 {
11585 new_return(89);
11586 }
11587 49152 }
11588
2/2
✓ Branch 0 taken 12288 times.
✓ Branch 1 taken 6144 times.
18432 for ( int32_t q = 0; q < 2; q++ )
11589 {
11590
1/2
✓ Branch 0 taken 12288 times.
✗ Branch 1 not taken.
12288 if(!p_iputl(guysbuf[i].initA[q],f))
11591 {
11592 new_return(90);
11593 }
11594 12288 }
11595
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].editorflags,f))
11596 {
11597 new_return(91);
11598 }
11599 //somehow forgot these in the older builds -Z
11600
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc13,f))
11601 {
11602 new_return(92);
11603 }
11604
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc14,f))
11605 {
11606 new_return(93);
11607 }
11608
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].misc15,f))
11609 {
11610 new_return(94);
11611 }
11612
11613 //Enemy Editor InitD[] labels
11614
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
11615 {
11616
2/2
✓ Branch 0 taken 3194880 times.
✓ Branch 1 taken 49152 times.
3244032 for ( int32_t w = 0; w < 65; w++ )
11617 {
11618
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if(!p_putc(guysbuf[i].initD_label[q][w],f))
11619 {
11620 new_return(95);
11621 }
11622 3194880 }
11623
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 3194880 times.
3244032 for ( int32_t w = 0; w < 65; w++ )
11624 {
11625
1/2
✓ Branch 0 taken 3194880 times.
✗ Branch 1 not taken.
3194880 if(!p_putc(guysbuf[i].weapon_initD_label[q][w],f))
11626 {
11627 new_return(96);
11628 }
11629 3194880 }
11630 49152 }
11631
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputw(guysbuf[i].weaponscript,f))
11632 {
11633 new_return(97);
11634 }
11635 //eweapon initD
11636
2/2
✓ Branch 0 taken 49152 times.
✓ Branch 1 taken 6144 times.
55296 for ( int32_t q = 0; q < 8; q++ )
11637 {
11638
1/2
✓ Branch 0 taken 49152 times.
✗ Branch 1 not taken.
49152 if(!p_iputl(guysbuf[i].weap_initiald[q],f))
11639 {
11640 new_return(98);
11641 }
11642 49152 }
11643
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_iputl(guysbuf[i].moveflags,f))
11644 new_return(99);
11645
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].spr_shadow,f))
11646 new_return(100);
11647
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].spr_death,f))
11648 new_return(101);
11649
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(!p_putc(guysbuf[i].spr_spawn,f))
11650 new_return(102);
11651 6144 }
11652
11653
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
11654 {
11655 6 section_size=writesize;
11656 6 }
11657 12 }
11658
11659
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
11660 {
11661 char ebuf[80];
11662 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
11663 jwin_alert("Error: writeguys()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
11664 }
11665
11666 6 new_return(0);
11667 }
11668
11669 6 int32_t writeherosprites(PACKFILE *f, zquestheader *Header)
11670 {
11671 //these are here to bypass compiler warnings about unused arguments
11672 6 Header=Header;
11673
11674 6 dword section_id=ID_HEROSPRITES;
11675 6 dword section_version=V_HEROSPRITES;
11676 6 dword section_cversion=CV_HEROSPRITES;
11677 6 dword section_size=0;
11678
11679 //section id
11680
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
11681 {
11682 new_return(1);
11683 }
11684
11685 //section version info
11686
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
11687 {
11688 new_return(2);
11689 }
11690
11691
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
11692 {
11693 new_return(3);
11694 }
11695
11696
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11697 {
11698 12 fake_pack_writing=(writecycle==0);
11699
11700 //section size
11701
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
11702 {
11703 new_return(4);
11704 }
11705
11706 12 writesize=0;
11707
11708 //finally... section data
11709
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11710 {
11711
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(walkspr[i][spr_tile],f))
11712 {
11713 new_return(5);
11714 }
11715
11716
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)walkspr[i][spr_flip],f))
11717 {
11718 new_return(5);
11719 }
11720
11721
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)walkspr[i][spr_extend],f))
11722 {
11723 new_return(5);
11724 }
11725 48 }
11726
11727
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11728 {
11729
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(stabspr[i][spr_tile],f))
11730 {
11731 new_return(6);
11732 }
11733
11734
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stabspr[i][spr_flip],f))
11735 {
11736 new_return(6);
11737 }
11738
11739
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stabspr[i][spr_extend],f))
11740 {
11741 new_return(6);
11742 }
11743 48 }
11744
11745
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11746 {
11747
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(slashspr[i][spr_tile],f))
11748 {
11749 new_return(7);
11750 }
11751
11752
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slashspr[i][spr_flip],f))
11753 {
11754 new_return(7);
11755 }
11756
11757
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slashspr[i][spr_extend],f))
11758 {
11759 new_return(7);
11760 }
11761 48 }
11762
11763
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11764 {
11765
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(floatspr[i][spr_tile],f))
11766 {
11767 new_return(8);
11768 }
11769
11770
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)floatspr[i][spr_flip],f))
11771 {
11772 new_return(8);
11773 }
11774
11775
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)floatspr[i][spr_extend],f))
11776 {
11777 new_return(8);
11778 }
11779 48 }
11780
11781
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11782 {
11783
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(swimspr[i][spr_tile],f))
11784 {
11785 new_return(8);
11786 }
11787
11788
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)swimspr[i][spr_flip],f))
11789 {
11790 new_return(8);
11791 }
11792
11793
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)swimspr[i][spr_extend],f))
11794 {
11795 new_return(8);
11796 }
11797 48 }
11798
11799
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11800 {
11801
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(divespr[i][spr_tile],f))
11802 {
11803 new_return(9);
11804 }
11805
11806
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)divespr[i][spr_flip],f))
11807 {
11808 new_return(9);
11809 }
11810
11811
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)divespr[i][spr_extend],f))
11812 {
11813 new_return(9);
11814 }
11815 48 }
11816
11817
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11818 {
11819
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(poundspr[i][spr_tile],f))
11820 {
11821 new_return(10);
11822 }
11823
11824
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)poundspr[i][spr_flip],f))
11825 {
11826 new_return(10);
11827 }
11828
11829
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)poundspr[i][spr_extend],f))
11830 {
11831 new_return(10);
11832 }
11833 48 }
11834
11835
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(castingspr[spr_tile],f))
11836 {
11837 new_return(11);
11838 }
11839
11840
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)castingspr[spr_flip],f))
11841 {
11842 new_return(11);
11843 }
11844
11845
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)castingspr[spr_extend],f))
11846 {
11847 new_return(11);
11848 }
11849
11850
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 12 times.
36 for(int32_t i=0; i<2; i++)
11851 {
11852
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 24 times.
96 for(int32_t j=0; j<spr_holdmax; j++)
11853 {
11854
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(holdspr[i][j][spr_tile],f))
11855 {
11856 new_return(12);
11857 }
11858
11859
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 if(!p_putc((byte)holdspr[i][j][spr_flip],f))
11860 {
11861 new_return(12);
11862 }
11863
11864
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 if(!p_putc((byte)holdspr[i][j][spr_extend],f))
11865 {
11866 new_return(12);
11867 }
11868 72 }
11869 24 }
11870
11871
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11872 {
11873
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(jumpspr[i][spr_tile],f))
11874 {
11875 new_return(13);
11876 }
11877
11878
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)jumpspr[i][spr_flip],f))
11879 {
11880 new_return(13);
11881 }
11882
11883
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)jumpspr[i][spr_extend],f))
11884 {
11885 new_return(13);
11886 }
11887 48 }
11888
11889
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
11890 {
11891
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(chargespr[i][spr_tile],f))
11892 {
11893 new_return(13);
11894 }
11895
11896
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)chargespr[i][spr_flip],f))
11897 {
11898 new_return(13);
11899 }
11900
11901
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)chargespr[i][spr_extend],f))
11902 {
11903 new_return(13);
11904 }
11905 48 }
11906
11907
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)zinit.hero_swim_speed,f))
11908 {
11909 new_return(14);
11910 }
11911
11912 //{ V_HEROSPRITES >= 7
11913
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11914 {
11915
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(frozenspr[q][spr_tile],f))
11916 new_return(15);
11917
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)frozenspr[q][spr_flip],f))
11918 new_return(15);
11919
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)frozenspr[q][spr_extend],f))
11920 new_return(15);
11921 48 }
11922
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11923 {
11924
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(frozen_waterspr[q][spr_tile],f))
11925 new_return(15);
11926
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)frozen_waterspr[q][spr_flip],f))
11927 new_return(15);
11928
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)frozen_waterspr[q][spr_extend],f))
11929 new_return(15);
11930 48 }
11931
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11932 {
11933
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(onfirespr[q][spr_tile],f))
11934 new_return(15);
11935
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)onfirespr[q][spr_flip],f))
11936 new_return(15);
11937
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)onfirespr[q][spr_extend],f))
11938 new_return(15);
11939 48 }
11940
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11941 {
11942
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(onfire_waterspr[q][spr_tile],f))
11943 new_return(15);
11944
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)onfire_waterspr[q][spr_flip],f))
11945 new_return(15);
11946
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)onfire_waterspr[q][spr_extend],f))
11947 new_return(15);
11948 48 }
11949
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11950 {
11951
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(diggingspr[q][spr_tile],f))
11952 new_return(15);
11953
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)diggingspr[q][spr_flip],f))
11954 new_return(15);
11955
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)diggingspr[q][spr_extend],f))
11956 new_return(15);
11957 48 }
11958
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11959 {
11960
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(usingrodspr[q][spr_tile],f))
11961 new_return(15);
11962
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)usingrodspr[q][spr_flip],f))
11963 new_return(15);
11964
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)usingrodspr[q][spr_extend],f))
11965 new_return(15);
11966 48 }
11967
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11968 {
11969
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(usingcanespr[q][spr_tile],f))
11970 new_return(15);
11971
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)usingcanespr[q][spr_flip],f))
11972 new_return(15);
11973
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)usingcanespr[q][spr_extend],f))
11974 new_return(15);
11975 48 }
11976
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11977 {
11978
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(pushingspr[q][spr_tile],f))
11979 new_return(15);
11980
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)pushingspr[q][spr_flip],f))
11981 new_return(15);
11982
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)pushingspr[q][spr_extend],f))
11983 new_return(15);
11984 48 }
11985
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11986 {
11987
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(liftingspr[q][spr_tile],f))
11988 new_return(15);
11989
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingspr[q][spr_flip],f))
11990 new_return(15);
11991
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingspr[q][spr_extend],f))
11992 new_return(15);
11993
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingspr[q][spr_frames],f))
11994 new_return(15);
11995 48 }
11996
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
11997 {
11998
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(liftingwalkspr[q][spr_tile],f))
11999 new_return(15);
12000
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingwalkspr[q][spr_flip],f))
12001 new_return(15);
12002
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)liftingwalkspr[q][spr_extend],f))
12003 new_return(15);
12004 48 }
12005
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12006 {
12007
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(stunnedspr[q][spr_tile],f))
12008 new_return(15);
12009
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stunnedspr[q][spr_flip],f))
12010 new_return(15);
12011
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stunnedspr[q][spr_extend],f))
12012 new_return(15);
12013 48 }
12014
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12015 {
12016
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(stunned_waterspr[q][spr_tile],f))
12017 new_return(15);
12018
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stunned_waterspr[q][spr_flip],f))
12019 new_return(15);
12020
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)stunned_waterspr[q][spr_extend],f))
12021 new_return(15);
12022 48 }
12023
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12024 {
12025
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(drowningspr[q][spr_tile],f))
12026 new_return(15);
12027
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)drowningspr[q][spr_flip],f))
12028 new_return(15);
12029
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)drowningspr[q][spr_extend],f))
12030 new_return(15);
12031 48 }
12032
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12033 {
12034
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(drowning_lavaspr[q][spr_tile],f))
12035 new_return(15);
12036
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)drowning_lavaspr[q][spr_flip],f))
12037 new_return(15);
12038
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)drowning_lavaspr[q][spr_extend],f))
12039 new_return(15);
12040 48 }
12041
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12042 {
12043
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(fallingspr[q][spr_tile],f))
12044 new_return(15);
12045
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)fallingspr[q][spr_flip],f))
12046 new_return(15);
12047
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)fallingspr[q][spr_extend],f))
12048 new_return(15);
12049 48 }
12050
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12051 {
12052
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(shockedspr[q][spr_tile],f))
12053 new_return(15);
12054
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)shockedspr[q][spr_flip],f))
12055 new_return(15);
12056
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)shockedspr[q][spr_extend],f))
12057 new_return(15);
12058 48 }
12059
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12060 {
12061
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(shocked_waterspr[q][spr_tile],f))
12062 new_return(15);
12063
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)shocked_waterspr[q][spr_flip],f))
12064 new_return(15);
12065
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)shocked_waterspr[q][spr_extend],f))
12066 new_return(15);
12067 48 }
12068
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12069 {
12070
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(pullswordspr[q][spr_tile],f))
12071 new_return(15);
12072
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)pullswordspr[q][spr_flip],f))
12073 new_return(15);
12074
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)pullswordspr[q][spr_extend],f))
12075 new_return(15);
12076 48 }
12077
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12078 {
12079
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(readingspr[q][spr_tile],f))
12080 new_return(15);
12081
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)readingspr[q][spr_flip],f))
12082 new_return(15);
12083
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)readingspr[q][spr_extend],f))
12084 new_return(15);
12085 48 }
12086
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12087 {
12088
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(slash180spr[q][spr_tile],f))
12089 new_return(15);
12090
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slash180spr[q][spr_flip],f))
12091 new_return(15);
12092
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slash180spr[q][spr_extend],f))
12093 new_return(15);
12094 48 }
12095
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12096 {
12097
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(slashZ4spr[q][spr_tile],f))
12098 new_return(15);
12099
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slashZ4spr[q][spr_flip],f))
12100 new_return(15);
12101
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)slashZ4spr[q][spr_extend],f))
12102 new_return(15);
12103 48 }
12104
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12105 {
12106
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(dashspr[q][spr_tile],f))
12107 new_return(15);
12108
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)dashspr[q][spr_flip],f))
12109 new_return(15);
12110
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)dashspr[q][spr_extend],f))
12111 new_return(15);
12112 48 }
12113
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12114 {
12115
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(bonkspr[q][spr_tile],f))
12116 new_return(15);
12117
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)bonkspr[q][spr_flip],f))
12118 new_return(15);
12119
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)bonkspr[q][spr_extend],f))
12120 new_return(15);
12121 48 }
12122
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
48 for(int32_t q = 0; q < 3; ++q) //Not directions; number of medallion sprs
12123 {
12124
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_iputl(medallionsprs[q][spr_tile],f))
12125 new_return(15);
12126
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_putc((byte)medallionsprs[q][spr_flip],f))
12127 new_return(15);
12128
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_putc((byte)medallionsprs[q][spr_extend],f))
12129 new_return(15);
12130 36 }
12131
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12132 {
12133
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimspr[q][spr_tile],f))
12134 new_return(16);
12135
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimspr[q][spr_flip],f))
12136 new_return(16);
12137
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimspr[q][spr_extend],f))
12138 new_return(16);
12139 48 }
12140
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12141 {
12142
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimslashspr[q][spr_tile],f))
12143 new_return(17);
12144
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimslashspr[q][spr_flip],f))
12145 new_return(17);
12146
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimslashspr[q][spr_extend],f))
12147 new_return(17);
12148 48 }
12149
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12150 {
12151
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimstabspr[q][spr_tile],f))
12152 new_return(17);
12153
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimstabspr[q][spr_flip],f))
12154 new_return(17);
12155
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimstabspr[q][spr_extend],f))
12156 new_return(17);
12157 48 }
12158
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12159 {
12160
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimpoundspr[q][spr_tile],f))
12161 new_return(17);
12162
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimpoundspr[q][spr_flip],f))
12163 new_return(17);
12164
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimpoundspr[q][spr_extend],f))
12165 new_return(17);
12166 48 }
12167
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12168 {
12169
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sideswimchargespr[q][spr_tile],f))
12170 new_return(18);
12171
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimchargespr[q][spr_flip],f))
12172 new_return(18);
12173
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sideswimchargespr[q][spr_extend],f))
12174 new_return(18);
12175 48 }
12176
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12177 {
12178
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(hammeroffsets[q],f))
12179 new_return(19);
12180 48 }
12181
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
48 for(int32_t q = 0; q < 3; ++q)
12182 {
12183
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_iputl(sideswimholdspr[q][spr_tile],f))
12184 new_return(20);
12185
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_putc((byte)sideswimholdspr[q][spr_flip],f))
12186 new_return(20);
12187
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(!p_putc((byte)sideswimholdspr[q][spr_extend],f))
12188 new_return(20);
12189 36 }
12190
12191
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(sideswimcastingspr[spr_tile],f))
12192 {
12193 new_return(21);
12194 }
12195
12196
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)sideswimcastingspr[spr_flip],f))
12197 {
12198 new_return(21);
12199 }
12200
12201
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc((byte)sideswimcastingspr[spr_extend],f))
12202 {
12203 new_return(21);
12204 }
12205
12206
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t q = 0; q < 4; ++q)
12207 {
12208
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(sidedrowningspr[q][spr_tile],f))
12209 new_return(22);
12210
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sidedrowningspr[q][spr_flip],f))
12211 new_return(22);
12212
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)sidedrowningspr[q][spr_extend],f))
12213 new_return(22);
12214 48 }
12215
12216
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t i=0; i<4; i++)
12217 {
12218
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(revslashspr[i][spr_tile],f))
12219 {
12220 new_return(23);
12221 }
12222
12223
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)revslashspr[i][spr_flip],f))
12224 {
12225 new_return(23);
12226 }
12227
12228
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_putc((byte)revslashspr[i][spr_extend],f))
12229 {
12230 new_return(23);
12231 }
12232 48 }
12233
12234
12235
2/2
✓ Branch 0 taken 1752 times.
✓ Branch 1 taken 12 times.
1764 for (int32_t q = 0; q < wMax; q++) // Player defense values
12236 {
12237
1/2
✓ Branch 0 taken 1752 times.
✗ Branch 1 not taken.
1752 if (!p_putc(hero_defence[q], f))
12238 new_return(15);
12239 1752 }
12240 //}
12241
12242
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
12243 {
12244 6 section_size=writesize;
12245 6 }
12246 12 }
12247
12248 //More data will come here
12249
12250
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
12251 {
12252 char ebuf[80];
12253 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12254 jwin_alert("Error: writeherosprites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12255 }
12256
12257 6 new_return(0);
12258 }
12259
12260 6 int32_t writesubscreens(PACKFILE *f, zquestheader *Header)
12261 {
12262 6 dword section_id=ID_SUBSCREEN;
12263 6 dword section_version=V_SUBSCREEN;
12264 6 dword section_cversion=CV_SUBSCREEN;
12265 6 dword section_size=0;
12266
12267 //section id
12268
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
12269 {
12270 new_return(1);
12271 }
12272
12273 //section version info
12274
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
12275 {
12276 new_return(2);
12277 }
12278
12279
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
12280 {
12281 new_return(3);
12282 }
12283
12284
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12285 {
12286 12 fake_pack_writing=(writecycle==0);
12287
12288 //section size
12289
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
12290 {
12291 new_return(4);
12292 }
12293
12294 12 writesize=0;
12295
12296 12 byte sz = subscreens_active.size();
12297
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(sz,f))
12298 new_return(5);
12299
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 12 times.
78 for(int32_t i=0; i<sz; i++)
12300 {
12301 66 int32_t ret = subscreens_active[i].write(f);
12302 66 fake_pack_writing=(writecycle==0);
12303
12304
1/2
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
66 if(ret!=0)
12305 new_return(ret);
12306 66 }
12307
12308 12 sz = subscreens_passive.size();
12309
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(sz,f))
12310 new_return(5);
12311
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 12 times.
62 for(int32_t i=0; i<sz; i++)
12312 {
12313 50 int32_t ret = subscreens_passive[i].write(f);
12314 50 fake_pack_writing=(writecycle==0);
12315
12316
1/2
✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
50 if(ret!=0)
12317 new_return(ret);
12318 50 }
12319
12320 12 sz = subscreens_overlay.size();
12321
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(sz,f))
12322 new_return(5);
12323
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 for(int32_t i=0; i<sz; i++)
12324 {
12325 int32_t ret = subscreens_overlay[i].write(f);
12326 fake_pack_writing=(writecycle==0);
12327
12328 if(ret!=0)
12329 new_return(ret);
12330 }
12331
12332
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
12333 {
12334 6 section_size=writesize;
12335 6 }
12336 12 }
12337
12338
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
12339 {
12340 char ebuf[80];
12341 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12342 jwin_alert("Error: writesubscreens()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12343 }
12344
12345 6 new_return(0);
12346 6 }
12347
12348 extern script_data *ffscripts[NUMSCRIPTFFC];
12349 extern script_data *itemscripts[NUMSCRIPTITEM];
12350 extern script_data *guyscripts[NUMSCRIPTGUYS];
12351 extern script_data *lwpnscripts[NUMSCRIPTWEAPONS];
12352 extern script_data *ewpnscripts[NUMSCRIPTWEAPONS];
12353 extern script_data *globalscripts[NUMSCRIPTGLOBAL];
12354 extern script_data *genericscripts[NUMSCRIPTSGENERIC];
12355 extern script_data *playerscripts[NUMSCRIPTPLAYER];
12356 extern script_data *screenscripts[NUMSCRIPTSCREEN];
12357 extern script_data *dmapscripts[NUMSCRIPTSDMAP];
12358 extern script_data *itemspritescripts[NUMSCRIPTSITEMSPRITE];
12359 extern script_data *comboscripts[NUMSCRIPTSCOMBODATA];
12360 extern script_data *subscreenscripts[NUMSCRIPTSSUBSCREEN];
12361
12362 6 int32_t writeffscript(PACKFILE *f, zquestheader *Header)
12363 {
12364 6 dword section_id = ID_FFSCRIPT;
12365 6 dword section_version = V_FFSCRIPT;
12366 6 dword section_cversion = CV_FFSCRIPT;
12367 6 dword section_size = 0;
12368 6 dword zasmmeta_version = METADATA_V;
12369 6 byte numscripts = 0;
12370 6 numscripts = numscripts; //to avoid unused variables warnings
12371
12372 //section id
12373
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
12374 {
12375 new_return(1);
12376 }
12377
12378 //section version info
12379
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
12380 {
12381 new_return(2);
12382 }
12383
12384
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_cversion,f))
12385 {
12386 new_return(3);
12387 }
12388
12389
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(zasmmeta_version,f))
12390 {
12391 new_return(4);
12392 }
12393
12394
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12395 {
12396 12 fake_pack_writing=(writecycle==0);
12397
12398 //section size
12399
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
12400 {
12401 new_return(5);
12402 }
12403
12404 12 writesize=0;
12405
12406
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
12407 {
12408 6144 int32_t ret = write_one_ffscript(f, Header, i, &ffscripts[i]);
12409 6144 fake_pack_writing=(writecycle==0);
12410
12411
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12412 {
12413 new_return(ret);
12414 }
12415 6144 }
12416
12417
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
12418 {
12419 3072 int32_t ret = write_one_ffscript(f, Header, i, &itemscripts[i]);
12420 3072 fake_pack_writing=(writecycle==0);
12421
12422
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12423 {
12424 new_return(ret);
12425 }
12426 3072 }
12427
12428
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
12429 {
12430 3072 int32_t ret = write_one_ffscript(f, Header, i, &guyscripts[i]);
12431 3072 fake_pack_writing=(writecycle==0);
12432
12433
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12434 {
12435 new_return(ret);
12436 }
12437 3072 }
12438
12439
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 script_data *fake = new script_data(ScriptType::None, 0);
12440
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12441 {
12442 3072 int32_t ret = write_one_ffscript(f, Header, i, &fake);
12443 3072 fake_pack_writing=(writecycle==0);
12444
12445
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12446 {
12447 new_return(ret);
12448 }
12449 3072 }
12450
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 delete fake;
12451
12452
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
12453 {
12454 3072 int32_t ret = write_one_ffscript(f, Header, i, &screenscripts[i]);
12455 3072 fake_pack_writing=(writecycle==0);
12456
12457
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12458 {
12459 new_return(ret);
12460 }
12461 3072 }
12462
12463
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
12464 {
12465 96 int32_t ret = write_one_ffscript(f, Header, i, &globalscripts[i]);
12466 96 fake_pack_writing=(writecycle==0);
12467
12468
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(ret!=0)
12469 {
12470 new_return(ret);
12471 }
12472 96 }
12473
12474
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 12 times.
72 for(int32_t i=0; i<NUMSCRIPTPLAYER; i++)
12475 {
12476 60 int32_t ret = write_one_ffscript(f, Header, i, &playerscripts[i]);
12477 60 fake_pack_writing=(writecycle==0);
12478
12479
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(ret!=0)
12480 {
12481 new_return(ret);
12482 }
12483 60 }
12484
12485
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12486 {
12487 3072 int32_t ret = write_one_ffscript(f, Header, i, &lwpnscripts[i]);
12488 3072 fake_pack_writing=(writecycle==0);
12489
12490
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12491 {
12492 new_return(ret);
12493 }
12494 3072 }
12495
12496
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12497 {
12498 3072 int32_t ret = write_one_ffscript(f, Header, i, &ewpnscripts[i]);
12499 3072 fake_pack_writing=(writecycle==0);
12500
12501
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12502 {
12503 new_return(ret);
12504 }
12505 3072 }
12506
12507
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
12508 {
12509 3072 int32_t ret = write_one_ffscript(f, Header, i, &dmapscripts[i]);
12510 3072 fake_pack_writing=(writecycle==0);
12511
12512
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12513 {
12514 new_return(ret);
12515 }
12516 3072 }
12517
12518
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
12519 {
12520 3072 int32_t ret = write_one_ffscript(f, Header, i, &itemspritescripts[i]);
12521 3072 fake_pack_writing=(writecycle==0);
12522
12523
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12524 {
12525 new_return(ret);
12526 }
12527 3072 }
12528
12529
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
12530 {
12531 6144 int32_t ret = write_one_ffscript(f, Header, i, &comboscripts[i]);
12532 6144 fake_pack_writing=(writecycle==0);
12533
12534
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12535 {
12536 new_return(ret);
12537 }
12538 6144 }
12539
12540
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSGENERIC,f))
12541 {
12542 new_return(2000);
12543 }
12544
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
12545 {
12546 6144 int32_t ret = write_one_ffscript(f, Header, i, &genericscripts[i]);
12547 6144 fake_pack_writing=(writecycle==0);
12548
12549
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12550 {
12551 new_return(ret);
12552 }
12553 6144 }
12554
12555
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
12556 {
12557 new_return(2001);
12558 }
12559
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
12560 {
12561 3072 int32_t ret = write_one_ffscript(f, Header, i, &subscreenscripts[i]);
12562 3072 fake_pack_writing=(writecycle==0);
12563
12564
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12565 {
12566 new_return(ret);
12567 }
12568 3072 }
12569
12570
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputl((int32_t)zScript.size(), f))
12571 {
12572 new_return(2001);
12573 }
12574
12575
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
12576 {
12577 new_return(2002);
12578 }
12579
12580 12 word numffcbindings=0;
12581
12582
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12583 {
12584
2/2
✓ Branch 0 taken 5932 times.
✓ Branch 1 taken 200 times.
6132 if(it->second.scriptname != "")
12585 {
12586 200 numffcbindings++;
12587 200 }
12588 6132 }
12589
12590
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numffcbindings, f))
12591 {
12592 new_return(2003);
12593 }
12594
12595
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12596 {
12597
2/2
✓ Branch 0 taken 5932 times.
✓ Branch 1 taken 200 times.
6132 if(it->second.scriptname != "")
12598 {
12599
1/2
✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
200 if(!p_iputw(it->first,f))
12600 {
12601 new_return(2004);
12602 }
12603
12604
1/2
✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
200 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12605 {
12606 new_return(2005);
12607 }
12608
12609
1/2
✓ Branch 0 taken 200 times.
✗ Branch 1 not taken.
200 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12610 {
12611 new_return(2006);
12612 }
12613 200 }
12614 6132 }
12615
12616 12 word numglobalbindings=0;
12617
12618
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12619 {
12620
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 24 times.
96 if(it->second.scriptname != "")
12621 {
12622 24 numglobalbindings++;
12623 24 }
12624 96 }
12625
12626
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numglobalbindings, f))
12627 {
12628 new_return(2007);
12629 }
12630
12631
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12632 {
12633
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 24 times.
96 if(it->second.scriptname != "")
12634 {
12635
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!p_iputw(it->first,f))
12636 {
12637 new_return(2008);
12638 }
12639
12640
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12641 {
12642 new_return(2009);
12643 }
12644
12645
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12646 {
12647 new_return(2010);
12648 }
12649 24 }
12650 96 }
12651
12652 12 word numitembindings=0;
12653
12654
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12655 {
12656
2/2
✓ Branch 0 taken 3036 times.
✓ Branch 1 taken 24 times.
3060 if(it->second.scriptname != "")
12657 {
12658 24 numitembindings++;
12659 24 }
12660 3060 }
12661
12662
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitembindings, f))
12663 {
12664 new_return(2011);
12665 }
12666
12667
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12668 {
12669
2/2
✓ Branch 0 taken 3036 times.
✓ Branch 1 taken 24 times.
3060 if(it->second.scriptname != "")
12670 {
12671
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!p_iputw(it->first,f))
12672 {
12673 new_return(2012);
12674 }
12675
12676
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12677 {
12678 new_return(2013);
12679 }
12680
12681
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12682 {
12683 new_return(2014);
12684 }
12685 24 }
12686 3060 }
12687
12688 //new script types
12689 //npc scripts
12690 12 word numnpcbindings=0;
12691
12692
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12693 {
12694
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12695 {
12696 numnpcbindings++;
12697 }
12698 3060 }
12699
12700
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numnpcbindings, f))
12701 {
12702 new_return(2015);
12703 }
12704
12705
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12706 {
12707
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12708 {
12709 if(!p_iputw(it->first,f))
12710 {
12711 new_return(2016);
12712 }
12713
12714 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12715 {
12716 new_return(2017);
12717 }
12718
12719 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12720 {
12721 new_return(2018);
12722 }
12723 }
12724 3060 }
12725
12726 //lweapon
12727
12728 12 word numlwpnbindings=0;
12729
12730
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12731 {
12732
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12733 {
12734 numlwpnbindings++;
12735 }
12736 3060 }
12737
12738
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numlwpnbindings, f))
12739 {
12740 new_return(2019);
12741 }
12742
12743
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12744 {
12745
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12746 {
12747 if(!p_iputw(it->first,f))
12748 {
12749 new_return(2020);
12750 }
12751
12752 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12753 {
12754 new_return(2021);
12755 }
12756
12757 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12758 {
12759 new_return(2022);
12760 }
12761 }
12762 3060 }
12763
12764 //////
12765
12766 //eweapon
12767
12768
12769 12 word numewpnbindings=0;
12770
12771
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12772 {
12773
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12774 {
12775 numewpnbindings++;
12776 }
12777 3060 }
12778
12779
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numewpnbindings, f))
12780 {
12781 new_return(2023);
12782 }
12783
12784
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12785 {
12786
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12787 {
12788 if(!p_iputw(it->first,f))
12789 {
12790 new_return(2024);
12791 }
12792
12793 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12794 {
12795 new_return(2025);
12796 }
12797
12798 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12799 {
12800 new_return(2026);
12801 }
12802 }
12803 3060 }
12804
12805 //player scripts
12806 12 word numherobindings=0;
12807
12808
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12809 {
12810
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 2 times.
48 if(it->second.scriptname != "")
12811 {
12812 2 numherobindings++;
12813 2 }
12814 48 }
12815
12816
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numherobindings, f))
12817 {
12818 new_return(2027);
12819 }
12820
12821
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12822 {
12823
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 2 times.
48 if(it->second.scriptname != "")
12824 {
12825
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
12826 {
12827 new_return(2028);
12828 }
12829
12830
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12831 {
12832 new_return(2029);
12833 }
12834
12835
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12836 {
12837 new_return(2030);
12838 }
12839 2 }
12840 48 }
12841
12842 //dmap scripts
12843 12 word numdmapbindings=0;
12844
12845
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12846 {
12847
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12848 {
12849 4 numdmapbindings++;
12850 4 }
12851 3060 }
12852
12853
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numdmapbindings, f))
12854 {
12855 new_return(2031);
12856 }
12857
12858
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12859 {
12860
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12861 {
12862
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputw(it->first,f))
12863 {
12864 new_return(2032);
12865 }
12866
12867
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12868 {
12869 new_return(2033);
12870 }
12871
12872
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12873 {
12874 new_return(2034);
12875 }
12876 4 }
12877 3060 }
12878
12879 //screen scripts
12880 12 word numscreenbindings=0;
12881
12882
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12883 {
12884
2/2
✓ Branch 0 taken 3044 times.
✓ Branch 1 taken 16 times.
3060 if(it->second.scriptname != "")
12885 {
12886 16 numscreenbindings++;
12887 16 }
12888 3060 }
12889
12890
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numscreenbindings, f))
12891 {
12892 new_return(2035);
12893 }
12894
12895
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12896 {
12897
2/2
✓ Branch 0 taken 3044 times.
✓ Branch 1 taken 16 times.
3060 if(it->second.scriptname != "")
12898 {
12899
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!p_iputw(it->first,f))
12900 {
12901 new_return(2036);
12902 }
12903
12904
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12905 {
12906 new_return(2037);
12907 }
12908
12909
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12910 {
12911 new_return(2038);
12912 }
12913 16 }
12914 3060 }
12915 //item sprite scripts
12916 12 word numitemspritebindings=0;
12917
12918
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12919 {
12920
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12921 {
12922 numitemspritebindings++;
12923 }
12924 3060 }
12925
12926
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitemspritebindings, f))
12927 {
12928 new_return(2039);
12929 }
12930
12931
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12932 {
12933
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12934 {
12935 if(!p_iputw(it->first,f))
12936 {
12937 new_return(2040);
12938 }
12939
12940 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12941 {
12942 new_return(2041);
12943 }
12944
12945 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12946 {
12947 new_return(2042);
12948 }
12949 }
12950 3060 }
12951
12952 //combo scripts
12953 12 word numcombobindings=0;
12954
12955
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12956 {
12957
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12958 {
12959 numcombobindings++;
12960 }
12961 6132 }
12962
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numcombobindings, f))
12963 {
12964 new_return(2043);
12965 }
12966
12967
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12968 {
12969
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12970 {
12971 if(!p_iputw(it->first,f))
12972 {
12973 new_return(2044);
12974 }
12975
12976 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12977 {
12978 new_return(2045);
12979 }
12980
12981 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12982 {
12983 new_return(2046);
12984 }
12985 }
12986 6132 }
12987 //subscreen scripts
12988 12 word numgenericbindings=0;
12989
12990
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12991 {
12992
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12993 {
12994 numgenericbindings++;
12995 }
12996 6132 }
12997
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numgenericbindings, f))
12998 {
12999 new_return(2043);
13000 }
13001
13002
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
13003 {
13004
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
13005 {
13006 if(!p_iputw(it->first,f))
13007 {
13008 new_return(2044);
13009 }
13010
13011 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13012 {
13013 new_return(2045);
13014 }
13015
13016 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13017 {
13018 new_return(2046);
13019 }
13020 }
13021 6132 }
13022
13023 //generic scripts
13024 12 word numsubscreenbindings=0;
13025
13026
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13027 {
13028
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
13029 {
13030 numsubscreenbindings++;
13031 }
13032 3060 }
13033
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numsubscreenbindings, f))
13034 {
13035 new_return(2047);
13036 }
13037
13038
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13039 {
13040
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
13041 {
13042 if(!p_iputw(it->first,f))
13043 {
13044 new_return(2048);
13045 }
13046
13047 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13048 {
13049 new_return(2049);
13050 }
13051
13052 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13053 {
13054 new_return(2050);
13055 }
13056 }
13057 3060 }
13058
13059
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13060 {
13061 6 section_size=writesize;
13062 6 }
13063 12 }
13064
13065
13066
13067
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13068 {
13069 char ebuf[80];
13070 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13071 jwin_alert("Error: writeffscript()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13072 }
13073
13074 6 new_return(0);
13075 //return 0; //this is just here to stomp the compiler from whining.
13076 //the irony is that it causes an "unreachable code" warning.
13077 6 }
13078
13079 46236 int32_t write_one_ffscript(PACKFILE *f, zquestheader *Header, int32_t i, script_data **script)
13080 {
13081 //these are here to bypass compiler warnings about unused arguments
13082 46236 Header=Header;
13083 46236 i=i;
13084
13085
2/2
✓ Branch 0 taken 9494 times.
✓ Branch 1 taken 36742 times.
46236 size_t num_commands = (*script)->zasm_script ? (*script)->zasm_script->size : 0;
13086
13087
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputl(num_commands,f))
13088 {
13089 new_return(6);
13090 }
13091
13092 //Metadata
13093 46236 zasm_meta const& tmeta = (*script)->meta;
13094
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.zasm_v,f))
13095 {
13096 new_return(7);
13097 }
13098
13099
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.meta_v,f))
13100 {
13101 new_return(8);
13102 }
13103
13104
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.ffscript_v,f))
13105 {
13106 new_return(9);
13107 }
13108
13109
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_putc((int)tmeta.script_type,f))
13110 {
13111 new_return(10);
13112 }
13113
13114
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(int32_t q = 0; q < 8; ++q)
13115 {
13116
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.run_idens[q],f))
13117 new_return(11);
13118 369888 }
13119
13120
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(int32_t q = 0; q < 8; ++q)
13121 {
13122
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putc(tmeta.run_types[q],f))
13123 {
13124 new_return(12);
13125 }
13126 369888 }
13127
13128
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_putc(tmeta.flags,f))
13129 {
13130 new_return(13);
13131 }
13132
13133
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.compiler_v1,f))
13134 {
13135 new_return(14);
13136 }
13137
13138
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.compiler_v2,f))
13139 {
13140 new_return(15);
13141 }
13142
13143
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.compiler_v3,f))
13144 {
13145 new_return(16);
13146 }
13147
13148
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_iputw(tmeta.compiler_v4,f))
13149 {
13150 new_return(17);
13151 }
13152
13153
1/2
✓ Branch 0 taken 46236 times.
✗ Branch 1 not taken.
46236 if(!p_putcstr(tmeta.script_name,f))
13154 new_return(18);
13155
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46236 times.
46236 if(!p_putcstr(tmeta.author,f))
13156 new_return(19);
13157
2/2
✓ Branch 0 taken 462360 times.
✓ Branch 1 taken 46236 times.
508596 for(auto q = 0; q < 10; ++q)
13158 {
13159
1/2
✓ Branch 0 taken 462360 times.
✗ Branch 1 not taken.
462360 if(!p_putcstr(tmeta.attributes[q],f))
13160 new_return(27);
13161
1/2
✓ Branch 0 taken 462360 times.
✗ Branch 1 not taken.
462360 if(!p_putwstr(tmeta.attributes_help[q],f))
13162 new_return(28);
13163 462360 }
13164
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(auto q = 0; q < 8; ++q)
13165 {
13166
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.attribytes[q],f))
13167 new_return(29);
13168
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.attribytes_help[q],f))
13169 new_return(30);
13170 369888 }
13171
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(auto q = 0; q < 8; ++q)
13172 {
13173
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.attrishorts[q],f))
13174 new_return(31);
13175
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.attrishorts_help[q],f))
13176 new_return(32);
13177 369888 }
13178
2/2
✓ Branch 0 taken 739776 times.
✓ Branch 1 taken 46236 times.
786012 for(auto q = 0; q < 16; ++q)
13179 {
13180
1/2
✓ Branch 0 taken 739776 times.
✗ Branch 1 not taken.
739776 if(!p_putcstr(tmeta.usrflags[q],f))
13181 new_return(33);
13182
1/2
✓ Branch 0 taken 739776 times.
✗ Branch 1 not taken.
739776 if(!p_putwstr(tmeta.usrflags_help[q],f))
13183 new_return(34);
13184 739776 }
13185
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(auto q = 0; q < 8; ++q)
13186 {
13187
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.initd[q],f))
13188 new_return(35);
13189
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.initd_help[q],f))
13190 new_return(36);
13191 369888 }
13192
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 46236 times.
416124 for(auto q = 0; q < 8; ++q)
13193 {
13194
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putc(tmeta.initd_type[q],f))
13195 new_return(37);
13196 369888 }
13197
13198
2/2
✓ Branch 0 taken 36742 times.
✓ Branch 1 taken 626452 times.
663194 for(int32_t j=0; j<num_commands; j++)
13199 {
13200 626452 auto& zas = (*script)->zasm_script->zasm[j];
13201
1/2
✓ Branch 0 taken 626452 times.
✗ Branch 1 not taken.
626452 if(!p_iputw(zas.command,f))
13202 {
13203 new_return(20);
13204 }
13205
13206
2/2
✓ Branch 0 taken 616958 times.
✓ Branch 1 taken 9494 times.
626452 if(zas.command==0xFFFF)
13207 {
13208 9494 break;
13209 }
13210 else
13211 {
13212
1/2
✓ Branch 0 taken 616958 times.
✗ Branch 1 not taken.
616958 if(!p_iputl(zas.arg1,f))
13213 {
13214 new_return(21);
13215 }
13216
13217
1/2
✓ Branch 0 taken 616958 times.
✗ Branch 1 not taken.
616958 if(!p_iputl(zas.arg2,f))
13218 {
13219 new_return(22);
13220 }
13221
13222
1/2
✓ Branch 0 taken 616958 times.
✗ Branch 1 not taken.
616958 if(!p_iputl(zas.arg3,f))
13223 {
13224 new_return(23);
13225 }
13226
13227 616958 uint32_t sz = 0;
13228
2/2
✓ Branch 0 taken 2770 times.
✓ Branch 1 taken 614188 times.
616958 if(zas.strptr)
13229 2770 sz = zas.strptr->size();
13230
1/2
✓ Branch 0 taken 616958 times.
✗ Branch 1 not taken.
616958 if(!p_iputl(sz,f))
13231 {
13232 new_return(23);
13233 }
13234
2/2
✓ Branch 0 taken 614188 times.
✓ Branch 1 taken 2770 times.
616958 if(sz)
13235 {
13236 2770 auto& str = *zas.strptr;
13237
2/2
✓ Branch 0 taken 222648 times.
✓ Branch 1 taken 2770 times.
225418 for(size_t q = 0; q < sz; ++q)
13238 {
13239
1/2
✓ Branch 0 taken 222648 times.
✗ Branch 1 not taken.
222648 if(!p_putc(str[q],f))
13240 {
13241 new_return(24);
13242 }
13243 222648 }
13244 2770 }
13245 616958 sz = 0;
13246
2/2
✓ Branch 0 taken 616844 times.
✓ Branch 1 taken 114 times.
616958 if(zas.vecptr)
13247 114 sz = zas.vecptr->size();
13248
1/2
✓ Branch 0 taken 616958 times.
✗ Branch 1 not taken.
616958 if(!p_iputl(sz,f))
13249 {
13250 new_return(25);
13251 }
13252
2/2
✓ Branch 0 taken 616844 times.
✓ Branch 1 taken 114 times.
616958 if(sz) //vector found
13253 {
13254 114 auto& vec = *zas.vecptr;
13255
2/2
✓ Branch 0 taken 850 times.
✓ Branch 1 taken 114 times.
964 for(size_t q = 0; q < sz; ++q)
13256 {
13257
1/2
✓ Branch 0 taken 850 times.
✗ Branch 1 not taken.
850 if(!p_iputl(vec[q],f))
13258 {
13259 new_return(26);
13260 }
13261 850 }
13262 114 }
13263 }
13264 616958 }
13265
13266 46236 new_return(0);
13267 }
13268
13269 extern SAMPLE customsfxdata[WAV_COUNT];
13270 extern uint8_t customsfxflag[WAV_COUNT>>3];
13271
13272 6 int32_t writesfx(PACKFILE *f, zquestheader *Header)
13273 {
13274 //these are here to bypass compiler warnings about unused arguments
13275 6 Header=Header;
13276
13277 6 dword section_id=ID_SFX;
13278 6 dword section_version=V_SFX;
13279 6 dword section_cversion=CV_SFX;
13280 6 dword section_size=0;
13281
13282 //section id
13283
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
13284 {
13285 new_return(1);
13286 }
13287
13288 //section version info
13289
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
13290 {
13291 new_return(2);
13292 }
13293
13294
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
13295 {
13296 new_return(3);
13297 }
13298
13299
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13300 {
13301 12 fake_pack_writing=(writecycle==0);
13302
13303 //section size
13304
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
13305 {
13306 new_return(4);
13307 }
13308
13309 12 writesize=0;
13310
13311
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 12 times.
396 for(int32_t i=0; i<WAV_COUNT>>3; i++)
13312 {
13313
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_putc(customsfxflag[i],f))
13314 {
13315 new_return(5);
13316 }
13317 384 }
13318
13319
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(int32_t i=1; i<WAV_COUNT; i++)
13320 {
13321
2/2
✓ Branch 0 taken 820 times.
✓ Branch 1 taken 2240 times.
3060 if(get_bit(customsfxflag, i-1) == 0)
13322 2240 continue;
13323
13324
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!pfwrite(sfx_string[i], 36, f))
13325 {
13326 new_return(5);
13327 }
13328 820 }
13329
13330
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(int32_t i=1; i<WAV_COUNT; i++)
13331 {
13332
2/2
✓ Branch 0 taken 820 times.
✓ Branch 1 taken 2240 times.
3060 if(get_bit(customsfxflag, i-1) == 0)
13333 2240 continue;
13334
13335
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].bits,f))
13336 {
13337 new_return(5);
13338 }
13339
13340
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].stereo,f))
13341 {
13342 new_return(6);
13343 }
13344
13345
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].freq,f))
13346 {
13347 new_return(7);
13348 }
13349
13350
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].priority,f))
13351 {
13352 new_return(8);
13353 }
13354
13355
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].len,f))
13356 {
13357 new_return(9);
13358 }
13359
13360
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].loop_start,f))
13361 {
13362 new_return(10);
13363 }
13364
13365
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].loop_end,f))
13366 {
13367 new_return(11);
13368 }
13369
13370
1/2
✓ Branch 0 taken 820 times.
✗ Branch 1 not taken.
820 if(!p_iputl(customsfxdata[i].param,f))
13371 {
13372 new_return(12);
13373 }
13374
13375 //de-endianfy the data
13376 820 int32_t wordstowrite = (customsfxdata[i].bits==8?1:2)*(customsfxdata[i].stereo==0?1:2)*customsfxdata[i].len/sizeof(word);
13377
13378
2/2
✓ Branch 0 taken 18594894 times.
✓ Branch 1 taken 820 times.
18595714 for(int32_t j=0; j<wordstowrite; j++)
13379 {
13380
1/2
✓ Branch 0 taken 18594894 times.
✗ Branch 1 not taken.
18594894 if(!p_iputw(((word *)customsfxdata[i].data)[j],f))
13381 {
13382 new_return(13);
13383 }
13384 18594894 }
13385 820 }
13386
13387
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13388 {
13389 6 section_size=writesize;
13390 6 }
13391 12 }
13392
13393
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13394 {
13395 char ebuf[80];
13396 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13397 jwin_alert("Error: writesfx()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13398 }
13399
13400 6 new_return(0);
13401 }
13402
13403 6 int32_t writeinitdata(PACKFILE *f, zquestheader *)
13404 {
13405 6 dword section_id=ID_INITDATA;
13406 6 dword section_version=V_INITDATA;
13407 6 dword section_cversion=CV_INITDATA;
13408 6 dword section_size = 0;
13409
13410 6 zinit.last_map=Map.getCurrMap();
13411 6 zinit.last_screen=Map.getCurrScr();
13412 6 zinit.normalize();
13413
13414 //section id
13415
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
13416 {
13417 new_return(1);
13418 }
13419
13420 //section version info
13421
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
13422 {
13423 new_return(2);
13424 }
13425
13426
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
13427 {
13428 new_return(3);
13429 }
13430
13431 //TODO
13432
13433
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13434 {
13435 12 fake_pack_writing=(writecycle==0);
13436
13437 //section size
13438
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
13439 new_return(4);
13440
13441 12 writesize=0;
13442
13443
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 12 times.
396 for(int q = 0; q < MAXITEMS/8; ++q)
13444
1/2
✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
384 if(!p_putc(zinit.items[q], f))
13445 new_return(5);
13446
2/2
✓ Branch 0 taken 768 times.
✓ Branch 1 taken 12 times.
780 for(int q = 0; q < MAXLEVELS/8; ++q)
13447 {
13448
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if(!p_putc(zinit.map[q], f))
13449 new_return(6);
13450
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if(!p_putc(zinit.compass[q], f))
13451 new_return(7);
13452
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if(!p_putc(zinit.boss_key[q], f))
13453 new_return(8);
13454
1/2
✓ Branch 0 taken 768 times.
✗ Branch 1 not taken.
768 if(!p_putc(zinit.mcguffin[q], f))
13455 new_return(9);
13456 768 }
13457
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbvec(zinit.level_keys, f))
13458 new_return(10);
13459
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(MAX_COUNTERS,f))
13460 new_return(11);
13461
2/2
✓ Branch 0 taken 1284 times.
✓ Branch 1 taken 12 times.
1296 for(int q = 0; q < MAX_COUNTERS; ++q)
13462
1/2
✓ Branch 0 taken 1284 times.
✗ Branch 1 not taken.
1284 if(!p_iputw(zinit.counter[q],f))
13463 new_return(12);
13464
2/2
✓ Branch 0 taken 1284 times.
✓ Branch 1 taken 12 times.
1296 for(int q = 0; q < MAX_COUNTERS; ++q)
13465
1/2
✓ Branch 0 taken 1284 times.
✗ Branch 1 not taken.
1284 if(!p_iputw(zinit.mcounter[q],f))
13466 new_return(13);
13467
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.bomb_ratio,f))
13468 new_return(14);
13469
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hcp,f))
13470 new_return(15);
13471
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hcp_per_hc,f))
13472 new_return(16);
13473
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.cont_heart,f))
13474 new_return(17);
13475
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hp_per_heart,f))
13476 new_return(18);
13477
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.magic_per_block,f))
13478 new_return(19);
13479
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hero_damage_multiplier,f))
13480 new_return(20);
13481
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.ene_damage_multiplier,f))
13482 new_return(21);
13483
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.dither_type,f))
13484 new_return(22);
13485
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.dither_arg,f))
13486 new_return(23);
13487
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.dither_percent,f))
13488 new_return(24);
13489
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.def_lightrad,f))
13490 new_return(25);
13491
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.transdark_percent,f))
13492 new_return(26);
13493
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.darkcol,f))
13494 new_return(27);
13495
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_x,f))
13496 new_return(28);
13497
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_y,f))
13498 new_return(29);
13499
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_xofs,f))
13500 new_return(30);
13501
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_yofs,f))
13502 new_return(31);
13503
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_grid_color,f))
13504 new_return(32);
13505
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_bbox_1_color,f))
13506 new_return(33);
13507
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_bbox_2_color,f))
13508 new_return(34);
13509
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.ss_flags,f))
13510 new_return(35);
13511
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbitstr(zinit.flags,f))
13512 new_return(36);
13513
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.last_map,f))
13514 new_return(37);
13515
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.last_screen,f))
13516 new_return(38);
13517
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.msg_more_x,f))
13518 new_return(39);
13519
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.msg_more_y,f))
13520 new_return(40);
13521
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.msg_more_is_offset,f))
13522 new_return(41);
13523
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.msg_speed,f))
13524 new_return(42);
13525
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.gravity,f))
13526 new_return(43);
13527
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.swimgravity,f))
13528 new_return(44);
13529
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.terminalv,f))
13530 new_return(45);
13531
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hero_swim_speed,f))
13532 new_return(46);
13533
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hero_swim_mult,f))
13534 new_return(47);
13535
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.hero_swim_div,f))
13536 new_return(48);
13537
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.heroSideswimUpStep,f))
13538 new_return(49);
13539
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.heroSideswimSideStep,f))
13540 new_return(50);
13541
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.heroSideswimDownStep,f))
13542 new_return(51);
13543
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.exitWaterJump,f))
13544 new_return(52);
13545
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.heroStep,f))
13546 new_return(53);
13547
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.heroAnimationStyle,f))
13548 new_return(54);
13549
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.jump_hero_layer_threshold,f))
13550 new_return(55);
13551
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(zinit.bunny_ltm,f))
13552 new_return(56);
13553
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.start_dmap,f))
13554 new_return(57);
13555
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(zinit.subscrSpeed,f))
13556 new_return(58);
13557
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.switchhookstyle,f))
13558 new_return(59);
13559
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putc(zinit.magicdrainrate,f))
13560 new_return(60);
13561
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputzf(zinit.shove_offset,f))
13562 new_return(61);
13563
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbitstr(zinit.gen_doscript, f))
13564 new_return(62);
13565
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_exitState, f))
13566 new_return(63);
13567
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_reloadState, f))
13568 new_return(64);
13569
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_initd, f))
13570 new_return(65);
13571
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_eventstate, f))
13572 new_return(66);
13573
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.gen_data, f))
13574 new_return(67);
13575
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_putbmap(zinit.screen_data, f))
13576 new_return(68);
13577
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_putc(zinit.spriteflickerspeed, f))
13578 new_return(69);
13579
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_putc(zinit.spriteflickercolor, f))
13580 new_return(70);
13581
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_putc(zinit.spriteflickertransp, f))
13582 new_return(71);
13583
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (!p_iputzf(zinit.air_drag, f))
13584 new_return(72);
13585
13586
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13587 {
13588 6 section_size=writesize;
13589 6 }
13590 12 }
13591
13592
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13593 {
13594 char ebuf[80];
13595 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13596 jwin_alert("Error: writeinitdata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13597 }
13598
13599 6 new_return(0);
13600 }
13601
13602 6 int32_t writeitemdropsets(PACKFILE *f, zquestheader *Header)
13603 {
13604 //these are here to bypass compiler warnings about unused arguments
13605 6 Header=Header;
13606
13607 6 dword section_id=ID_ITEMDROPSETS;
13608 6 dword section_version=V_ITEMDROPSETS;
13609 6 dword section_cversion=CV_ITEMDROPSETS;
13610 // dword section_size=0;
13611 6 dword section_size = 0;
13612 6 word num_item_drop_sets=count_item_drop_sets();
13613
13614 //section id
13615
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
13616 {
13617 new_return(1);
13618 }
13619
13620 //section version info
13621
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
13622 {
13623 new_return(2);
13624 }
13625
13626
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
13627 {
13628 new_return(3);
13629 }
13630
13631
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13632 {
13633 12 fake_pack_writing=(writecycle==0);
13634
13635 //section size
13636
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
13637 {
13638 new_return(4);
13639 }
13640
13641 12 writesize=0;
13642
13643 //finally... section data
13644
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(num_item_drop_sets,f))
13645 {
13646 new_return(5);
13647 }
13648
13649
2/2
✓ Branch 0 taken 158 times.
✓ Branch 1 taken 12 times.
170 for(int32_t i=0; i<num_item_drop_sets; i++)
13650 {
13651
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!pfwrite(item_drop_sets[i].name, sizeof(item_drop_sets[i].name)-1, f))
13652 {
13653 new_return(6);
13654 }
13655
13656
2/2
✓ Branch 0 taken 1580 times.
✓ Branch 1 taken 158 times.
1738 for(int32_t j=0; j<10; ++j)
13657 {
13658
1/2
✓ Branch 0 taken 1580 times.
✗ Branch 1 not taken.
1580 if(!p_iputw(item_drop_sets[i].item[j],f))
13659 {
13660 new_return(7);
13661 }
13662 1580 }
13663
13664
2/2
✓ Branch 0 taken 1738 times.
✓ Branch 1 taken 158 times.
1896 for(int32_t j=0; j<11; ++j)
13665 {
13666
1/2
✓ Branch 0 taken 1738 times.
✗ Branch 1 not taken.
1738 if(!p_iputw(item_drop_sets[i].chance[j],f))
13667 {
13668 new_return(8);
13669 }
13670 1738 }
13671 158 }
13672
13673
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13674 {
13675 6 section_size=writesize;
13676 6 }
13677 12 }
13678
13679
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13680 {
13681 char ebuf[80];
13682 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13683 jwin_alert("Error: writeitemdropsets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13684 }
13685
13686 6 new_return(0);
13687 }
13688
13689 6 int32_t writefavorites(PACKFILE *f, zquestheader*)
13690 {
13691 6 dword section_id=ID_FAVORITES;
13692 6 dword section_version=V_FAVORITES;
13693 6 dword section_cversion=CV_FAVORITES;
13694 6 dword section_size = 0;
13695
13696 //section id
13697
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
13698 {
13699 new_return(1);
13700 }
13701
13702 //section version info
13703
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
13704 {
13705 new_return(2);
13706 }
13707
13708
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(section_cversion,f))
13709 {
13710 new_return(3);
13711 }
13712
13713
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13714 {
13715 12 fake_pack_writing=(writecycle==0);
13716
13717 //section size
13718
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
13719 new_return(4);
13720
13721 12 writesize=0;
13722
13723
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(FAVORITECOMBO_PER_ROW,f))
13724 new_return(16);
13725
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(FAVORITECOMBO_PER_PAGE,f)) // Just in case pages get resized again
13726 new_return(17);
13727
13728 12 word favcmb_cnt = 0;
13729
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 14918 times.
14922 for(int q = MAXFAVORITECOMBOS-1; q >= 0; --q)
13730
2/2
✓ Branch 0 taken 14910 times.
✓ Branch 1 taken 8 times.
14918 if(favorite_combos[q] != -1)
13731 {
13732 8 favcmb_cnt = q+1;
13733 8 break;
13734 }
13735
13736
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(favcmb_cnt,f)) // This'll probably never change, huh?
13737 new_return(5);
13738
13739
2/2
✓ Branch 0 taken 210 times.
✓ Branch 1 taken 12 times.
222 for(int i=0; i<favcmb_cnt; ++i)
13740 {
13741
1/2
✓ Branch 0 taken 210 times.
✗ Branch 1 not taken.
210 if (!p_putc(favorite_combo_modes[i], f))
13742 new_return(6);
13743
1/2
✓ Branch 0 taken 210 times.
✗ Branch 1 not taken.
210 if (!p_iputl(favorite_combos[i], f))
13744 new_return(7);
13745 210 }
13746
13747
13748 12 word max_combo_cols = MAX_COMBO_COLS;
13749
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(max_combo_cols,f))
13750 new_return(9);
13751
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int q = 0; q < max_combo_cols; ++q)
13752 {
13753
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(First[q],f))
13754 new_return(10);
13755
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(combo_alistpos[q],f))
13756 new_return(11);
13757
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(combo_pool_listpos[q],f))
13758 new_return(12);
13759 48 }
13760 12 word max_mappages = MAX_MAPPAGE_BTNS;
13761
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputw(max_mappages,f))
13762 new_return(13);
13763
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 12 times.
120 for(int q = 0; q < max_mappages; ++q)
13764 {
13765
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 if(!p_iputl(map_page[q].map,f))
13766 new_return(14);
13767
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 if(!p_iputl(map_page[q].screen,f))
13768 new_return(15);
13769 108 }
13770
13771
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
13772 {
13773 6 section_size=writesize;
13774 6 }
13775 12 }
13776
13777
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
13778 {
13779 char ebuf[80];
13780 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13781 jwin_alert("Error: writefavorites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13782 }
13783
13784 6 new_return(0);
13785 }
13786
13787 6 static int32_t _save_unencoded_quest_int(const char *filename, bool compressed, const char *afname)
13788 {
13789
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!afname) afname = filename;
13790 6 reset_combo_animations();
13791 6 reset_combo_animations2();
13792 6 strcpy(header.id_str,QH_NEWIDSTR);
13793 6 header.zelda_version = ZELDA_VERSION;
13794 6 header.internal = INTERNAL_VERSION;
13795 // header.str_count = msg_count;
13796 // header.data_flags[ZQ_TILES] = usetiles;
13797 6 header.data_flags[ZQ_TILES] = true;
13798 6 header.data_flags[ZQ_CHEATS2] = 1;
13799 6 header.build=VERSION_BUILD;
13800
13801
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 6 times.
1518 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
13802 {
13803 1512 set_bit(midi_flags,i,int32_t(customtunes[i].data!=NULL));
13804 1512 }
13805
13806 char zinfofilename[2048];
13807 6 replace_extension(zinfofilename, afname, "zinfo", 2047);
13808
13809 6 box_start(1, "Saving Quest", get_zc_font(font_lfont), font, true);
13810 6 box_out("Saving Quest...");
13811 6 box_eol();
13812 6 box_eol();
13813
13814
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 std::string tmp_filename = util::create_temp_file_path(filename);
13815
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 PACKFILE *f = pack_fopen_password(tmp_filename.c_str(),compressed?F_WRITE_PACKED:F_WRITE, "");
13816
13817
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!f)
13818 return 1;
13819
13820
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Header...");
13821
13822
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writeheader(f,&header)!=0)
13823 return 2;
13824
13825
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13826
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13827
13828
13829
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(header.external_zinfo)
13830 {
13831 PACKFILE *inf = pack_fopen_password(zinfofilename, F_WRITE, "");
13832
13833 box_out("Writing ZInfo...");
13834 if(inf)
13835 {
13836 if(writezinfo(inf,ZI)!=0)
13837 return 2;
13838
13839 pack_fclose(inf);
13840 box_out("okay.");
13841 }
13842 else box_out(" ...file failure");
13843 box_eol();
13844 }
13845 else
13846 {
13847
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing ZInfo...");
13848
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writezinfo(f,ZI)!=0)
13849 return 2;
13850
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13851
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13852 }
13853
13854
13855
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Rules...");
13856
13857
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writerules(f,&header)!=0)
13858 return 3;
13859
13860
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13861
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13862
13863
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Strings...");
13864
13865
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)!=0)
13866 return 4;
13867
13868
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13869
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13870
13871
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Doors...");
13872
13873
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writedoorcombosets(f,&header)!=0)
13874 return 5;
13875
13876
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13877
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13878
13879
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing DMaps...");
13880
13881
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writedmaps(f,header.zelda_version,header.build,0,MAXDMAPS)!=0)
13882 return 6;
13883
13884
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13885
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13886
13887
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing &QMisc. Data...");
13888
13889
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writemisc(f,&header)!=0)
13890 return 7;
13891
13892
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13893
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13894
13895
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing &QMisc. Colors...");
13896
13897
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writemisccolors(f,&header)!=0)
13898 return 8;
13899
13900
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13901
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13902
13903
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Game Icons...");
13904
13905
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writegameicons(f,&header)!=0)
13906 return 9;
13907
13908
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13909
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13910
13911
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Items...");
13912
13913
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeitems(f,&header)!=0)
13914 return 10;
13915
13916
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13917
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13918
13919
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Weapons...");
13920
13921
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writeweapons(f,&header)!=0)
13922 return 11;
13923
13924
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13925
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13926
13927
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Maps...");
13928
13929
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writemaps(f,&header)!=0)
13930 return 12;
13931
13932
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13933
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13934
13935
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Combos...");
13936
13937
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writecombos(f,header.zelda_version,header.build,0,MAXCOMBOS)!=0)
13938 return 13;
13939
13940
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13941
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13942
13943
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Combo Aliases...");
13944
13945
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writecomboaliases(f,header.zelda_version,header.build)!=0)
13946 return 14;
13947
13948
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13949
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13950
13951
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Color Data...");
13952
13953
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writecolordata(f,header.zelda_version,header.build,0,newerpdTOTAL)!=0)
13954 return 15;
13955
13956
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13957
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13958
13959
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Tiles...");
13960
13961
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writetiles(f,header.zelda_version,header.build,0,NEWMAXTILES)!=0)
13962 return 16;
13963
13964
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13965
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13966
13967
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing MIDIs...");
13968
13969
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writemidis(f)!=0)
13970 return 17;
13971
13972
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13973
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13974
13975
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Cheat Codes...");
13976
13977
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writecheats(f,&header)!=0)
13978 return 18;
13979
13980
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13981
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13982
13983
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Init. Data...");
13984
13985
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeinitdata(f,&header)!=0)
13986 return 19;
13987
13988
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13989
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13990
13991
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Custom Guy Data...");
13992
13993
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeguys(f,&header)!=0)
13994 return 20;
13995
13996
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
13997
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
13998
13999
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Custom Player Sprite Data...");
14000
14001
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeherosprites(f,&header)!=0)
14002 return 21;
14003
14004
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14005
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14006
14007
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Custom Subscreen Data...");
14008
14009
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writesubscreens(f,&header)!=0)
14010 return 22;
14011
14012
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14013
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14014
14015
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing FF Script Data...");
14016
14017
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writeffscript(f,&header)!=0)
14018 return 23;
14019
14020
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14021
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14022
14023
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing SFX Data...");
14024
14025
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writesfx(f,&header)!=0)
14026 return 24;
14027
14028
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14029
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14030
14031
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Item Drop Sets...");
14032
14033
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(writeitemdropsets(f, &header)!=0)
14034 return 25;
14035
14036
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14037
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14038
14039
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("Writing Favorite Combos...");
14040
14041
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(writefavorites(f, &header)!=0)
14042 return 26;
14043
14044
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_out("okay.");
14045
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 box_eol();
14046
14047
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 pack_fclose(f);
14048
14049
14050
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
6 if(header.use_keyfile&&header.dirty_password)
14051 {
14052 char const* kfname = filename;
14053 char keyfilename[2048]={0};
14054 zprint2("Writing key files for '%s'\n", kfname, ".zpwd", ".zcheat");
14055
14056 char temp_pw[QSTPWD_LEN] = {0};
14057 uint ind = 0;
14058 for(char const* ext : {"key","zpwd","zcheat"})
14059 {
14060 replace_extension(keyfilename, kfname, ext, 2047);
14061 PACKFILE *fp = pack_fopen_password(keyfilename, F_WRITE, "");
14062 char msg[80] = {0};
14063 sprintf(msg, "ZQuest Auto-Generated Quest Password Key File. DO NOT EDIT!");
14064 msg[78]=13;
14065 msg[79]=10;
14066 pfwrite(msg, 80, fp);
14067 p_iputw(header.zelda_version,fp);
14068 p_putc(header.build,fp);
14069 char const* pwd = header.password;
14070 if(ind == 2) //.zcheat, hashed pwd
14071 {
14072 char hashmap = 'Z';
14073 hashmap += 'Q';
14074 hashmap += 'U';
14075 hashmap += 'E';
14076 hashmap += 'S';
14077 hashmap += 'T';
14078 for ( int q = 0; q < QSTPWD_LEN; ++q )
14079 {
14080 temp_pw[q] = header.password[q];
14081 temp_pw[q] += hashmap;
14082 }
14083 pwd = temp_pw;
14084 }
14085 pfwrite(pwd, strlen(pwd), fp);
14086 pack_fclose(fp);
14087 ++ind;
14088 }
14089 }
14090
14091 // Move file to destination at end, to avoid issues with file being unavailable to test mode.
14092 6 std::error_code ec;
14093
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 fs::rename(tmp_filename, filename, ec);
14094
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (ec)
14095 {
14096 al_trace("Error saving: %s\n", std::strerror(ec.value()));
14097 return ec.value();
14098 }
14099
14100
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 strncpy(header.zelda_version_string, getVersionString(), sizeof(header.zelda_version_string));
14101
14102 #ifdef __EMSCRIPTEN__
14103 em_sync_fs();
14104 #endif
14105
14106 6 return 0;
14107 6 }
14108
14109 // #ifdef _WIN32
14110 // static std::time_t to_time_t(FILETIME const& ft) {
14111 // uint64_t t = (static_cast<uint64_t>(ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
14112 // t -= 116444736000000000ull;
14113 // t /= 10000000u;
14114 // return static_cast<std::time_t>(t);
14115 // }
14116 // #else
14117 // #endif
14118 template<typename TP>
14119 4 static std::time_t to_time_t(TP tp) {
14120 using namespace std::chrono;
14121 4 auto sctp = time_point_cast<system_clock::duration>(tp - TP::clock::now() + system_clock::now());
14122 4 return system_clock::to_time_t(sctp);
14123 }
14124
14125 4 std::string get_time_last_modified_string(std::string path)
14126 {
14127
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 auto write_time = fs::last_write_time(path);
14128 // TODO: C++20 but not supported yet.
14129 // auto tt = std::chrono::clock_cast<std::chrono::system_clock>(write_time);
14130 4 std::time_t tt = to_time_t(write_time);
14131 4 std::tm *gmt = std::gmtime(&tt);
14132 4 std::stringstream buffer;
14133
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 buffer << std::put_time(gmt, "%Y-%m-%d");
14134
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 std::string formattedFileTime = buffer.str();
14135 4 return formattedFileTime;
14136
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 }
14137
14138 6 int32_t save_unencoded_quest(const char *filename, bool compressed, const char *afname)
14139 {
14140 // Always backup quest if it was last saved in a different version of the editor,
14141 // or if this a new file and is overwritting another qst file.
14142
10/16
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 4 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 4 times.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 4 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
6 if (exists(filename) && std::string(getVersionString()) != header.zelda_version_string)
14143 {
14144 4 std::string backup_name;
14145
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 std::string last_mod = get_time_last_modified_string(filename);
14146
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (strlen(header.zelda_version_string) > 0)
14147 {
14148
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 backup_name = fmt::format("{}-v{}", last_mod, header.zelda_version_string);
14149 4 }
14150 else
14151 {
14152 backup_name = fmt::format("{}", last_mod);
14153 }
14154
7/14
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 4 times.
✗ Branch 13 not taken.
4 std::string backup_fname = fmt::format("{}-{}{}", fs::path(filename).stem().string(), backup_name, fs::path(filename).extension().string());
14155
3/6
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4 fs::path backup_path = fs::path("backups") / backup_fname;
14156
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 if (!fs::exists(backup_path))
14157 {
14158
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 fs::create_directories(fs::path("backups"));
14159
3/6
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4 if (fs::copy_file(filename, backup_path))
14160 {
14161
5/10
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 4 times.
4 InfoDialog("Quest Backup", fmt::format("A backup has been saved to {}", backup_path.string())).show();
14162 4 }
14163 else
14164 {
14165 InfoDialog("Quest Backup", fmt::format("Failed to save backup at {}", backup_path.string())).show();
14166 }
14167 4 }
14168 4 }
14169
14170 6 auto ret = _save_unencoded_quest_int(filename,compressed,afname);
14171 6 fake_pack_writing = false;
14172
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(ret)
14173 {
14174 box_out("-- Error saving quest file! --");
14175 box_end(true);
14176 }
14177 6 else box_end(false);
14178 6 return ret;
14179 }
14180
14181 6 int32_t save_quest(const char *filename, bool timed_save)
14182 {
14183
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 int32_t retention=timed_save?AutoSaveRetention:AutoBackupRetention;
14184
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 bool compress=!(timed_save&&UncompressedAutoSaves);
14185 char ext1[5];
14186 6 ext1[0]=0;
14187
14188
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(timed_save)
14189 {
14190 sprintf(ext1, "qt");
14191 }
14192 else
14193 {
14194 6 sprintf(ext1, "qb");
14195 }
14196
14197
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(retention)
14198 {
14199 char backupname[2048];
14200 char backupname2[2048];
14201 char ext[12];
14202
14203 for(int32_t i=retention-1; i>0; --i)
14204 {
14205 sprintf(ext, "%s%d", ext1, i-1);
14206 replace_extension(backupname, filepath, ext, 2047);
14207
14208 if(exists(backupname))
14209 {
14210 sprintf(ext, "%s%d", ext1, i);
14211 replace_extension(backupname2, filepath, ext, 2047);
14212
14213 if(exists(backupname2))
14214 {
14215 remove(backupname2);
14216 }
14217
14218 rename(backupname, backupname2);
14219 }
14220 }
14221
14222 //don't do this if we're not saving to the same name -DD
14223 if(!timed_save && !strcmp(filepath, filename))
14224 {
14225 sprintf(ext, "%s%d", ext1, 0);
14226 replace_extension(backupname, filepath, ext, 2047);
14227 rename(filepath, backupname);
14228 }
14229 }
14230
14231 int32_t ret;
14232 6 ret = save_unencoded_quest(filename, compress, filename);
14233
14234 6 return ret;
14235 }
14236
14237 6 void center_zq_class_dialogs()
14238 {
14239 6 jwin_center_dialog(pwd_dlg);
14240 6 }
14241
14242 void zmap::prv_secrets(bool high16only)
14243 {
14244 mapscr *s = &prvscr;
14245 mapscr *t = prvlayers;
14246 int32_t ft=0;
14247
14248 for(int32_t i=0; i<176; i++)
14249 {
14250 bool putit;
14251
14252 if(!high16only)
14253 {
14254 for(int32_t j=-1; j<6; j++)
14255 {
14256 int32_t newflag = -1;
14257
14258 for(int32_t iter=0; iter<2; ++iter)
14259 {
14260 putit=true;
14261
14262 if(!t[j].valid)
14263 continue;
14264
14265 int32_t checkflag=combobuf[t[j].data[i]].flag;
14266
14267 if(iter==1)
14268 {
14269 checkflag=t[j].sflag[i];
14270 }
14271
14272 switch(checkflag)
14273 {
14274 case mfANYFIRE:
14275 ft=sBCANDLE;
14276 break;
14277
14278 case mfSTRONGFIRE:
14279 ft=sRCANDLE;
14280 break;
14281
14282 case mfMAGICFIRE:
14283 ft=sWANDFIRE;
14284 break;
14285
14286 case mfDIVINEFIRE:
14287 ft=sDIVINEFIRE;
14288 break;
14289
14290 case mfARROW:
14291 ft=sARROW;
14292 break;
14293
14294 case mfSARROW:
14295 ft=sSARROW;
14296 break;
14297
14298 case mfGARROW:
14299 ft=sGARROW;
14300 break;
14301
14302 case mfSBOMB:
14303 ft=sSBOMB;
14304 break;
14305
14306 case mfBOMB:
14307 ft=sBOMB;
14308 break;
14309
14310 case mfBRANG:
14311 ft=sBRANG;
14312 break;
14313
14314 case mfMBRANG:
14315 ft=sMBRANG;
14316 break;
14317
14318 case mfFBRANG:
14319 ft=sFBRANG;
14320 break;
14321
14322 case mfWANDMAGIC:
14323 ft=sWANDMAGIC;
14324 break;
14325
14326 case mfREFMAGIC:
14327 ft=sREFMAGIC;
14328 break;
14329
14330 case mfREFFIREBALL:
14331 ft=sREFFIREBALL;
14332 break;
14333
14334 case mfSWORD:
14335 ft=sSWORD;
14336 break;
14337
14338 case mfWSWORD:
14339 ft=sWSWORD;
14340 break;
14341
14342 case mfMSWORD:
14343 ft=sMSWORD;
14344 break;
14345
14346 case mfXSWORD:
14347 ft=sXSWORD;
14348 break;
14349
14350 case mfSWORDBEAM:
14351 ft=sSWORDBEAM;
14352 break;
14353
14354 case mfWSWORDBEAM:
14355 ft=sWSWORDBEAM;
14356 break;
14357
14358 case mfMSWORDBEAM:
14359 ft=sMSWORDBEAM;
14360 break;
14361
14362 case mfXSWORDBEAM:
14363 ft=sXSWORDBEAM;
14364 break;
14365
14366 case mfHOOKSHOT:
14367 ft=sHOOKSHOT;
14368 break;
14369
14370 case mfWAND:
14371 ft=sWAND;
14372 break;
14373
14374 case mfHAMMER:
14375 ft=sHAMMER;
14376 break;
14377
14378 case mfSTRIKE:
14379 ft=sSTRIKE;
14380 break;
14381
14382 default:
14383 putit = false;
14384 break;
14385 }
14386
14387 if(putit)
14388 {
14389 if(j==-1)
14390 {
14391 s->data[i] = s->secretcombo[ft];
14392 s->cset[i] = s->secretcset[ft];
14393 newflag = s->secretflag[ft];
14394 }
14395 else
14396 {
14397 t[j].data[i] = t[j].secretcombo[ft];
14398 t[j].cset[i] = t[j].secretcset[ft];
14399 newflag = t[j].secretflag[ft];
14400 }
14401 }
14402 }
14403
14404 if(newflag >-1)
14405 {
14406 ((j==-1) ? s->sflag[i] : t[j].sflag[i]) = newflag;
14407 }
14408 }
14409 }
14410
14411 //if(true)
14412 //{
14413 int32_t newflag = -1;
14414
14415 for(int32_t iter=0; iter<2; ++iter)
14416 {
14417 int32_t checkflag=combobuf[s->data[i]].flag;
14418
14419 if(iter==1)
14420 {
14421 checkflag=s->sflag[i];
14422 }
14423
14424 if((checkflag > 15)&&(checkflag < 32))
14425 {
14426 s->data[i] = s->secretcombo[(checkflag)-16+4];
14427 s->cset[i] = s->secretcset[(checkflag)-16+4];
14428 newflag = s->secretflag[(checkflag)-16+4];
14429 // putit = true;
14430 }
14431 }
14432
14433 if(newflag >-1) s->sflag[i] = newflag;
14434
14435 for(int32_t j=0; j<6; j++)
14436 {
14437 if(!t[j].valid) continue;
14438
14439 int32_t newflag2 = -1;
14440
14441 for(int32_t iter=0; iter<2; ++iter)
14442 {
14443 int32_t checkflag=combobuf[t[j].data[i]].flag;
14444
14445 if(iter==1)
14446 {
14447 checkflag=t[j].sflag[i];
14448 }
14449
14450 if((checkflag > 15)&&(checkflag < 32))
14451 {
14452 t[j].data[i] = t[j].secretcombo[(checkflag)-16+4];
14453 t[j].cset[i] = t[j].secretcset[(checkflag)-16+4];
14454 newflag2 = t[j].secretflag[(checkflag)-16+4];
14455 }
14456 }
14457
14458 if(newflag2 >-1) t[j].sflag[i] = newflag2;
14459 }
14460 }
14461
14462 //FFCs
14463 word c = s->numFFC();
14464 for(word i=0; i<c; ++i)
14465 {
14466 bool putit;
14467
14468 if(!high16only)
14469 {
14470 for(int32_t iter=0; iter<1; ++iter)
14471 {
14472 putit=true;
14473 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
14474
14475 if(iter==1)
14476 {
14477 checkflag=s->sflag[i];
14478 }
14479
14480 switch(checkflag)
14481 {
14482 case mfANYFIRE:
14483 ft=sBCANDLE;
14484 break;
14485
14486 case mfSTRONGFIRE:
14487 ft=sRCANDLE;
14488 break;
14489
14490 case mfMAGICFIRE:
14491 ft=sWANDFIRE;
14492 break;
14493
14494 case mfDIVINEFIRE:
14495 ft=sDIVINEFIRE;
14496 break;
14497
14498 case mfARROW:
14499 ft=sARROW;
14500 break;
14501
14502 case mfSARROW:
14503 ft=sSARROW;
14504 break;
14505
14506 case mfGARROW:
14507 ft=sGARROW;
14508 break;
14509
14510 case mfSBOMB:
14511 ft=sSBOMB;
14512 break;
14513
14514 case mfBOMB:
14515 ft=sBOMB;
14516 break;
14517
14518 case mfBRANG:
14519 ft=sBRANG;
14520 break;
14521
14522 case mfMBRANG:
14523 ft=sMBRANG;
14524 break;
14525
14526 case mfFBRANG:
14527 ft=sFBRANG;
14528 break;
14529
14530 case mfWANDMAGIC:
14531 ft=sWANDMAGIC;
14532 break;
14533
14534 case mfREFMAGIC:
14535 ft=sREFMAGIC;
14536 break;
14537
14538 case mfREFFIREBALL:
14539 ft=sREFFIREBALL;
14540 break;
14541
14542 case mfSWORD:
14543 ft=sSWORD;
14544 break;
14545
14546 case mfWSWORD:
14547 ft=sWSWORD;
14548 break;
14549
14550 case mfMSWORD:
14551 ft=sMSWORD;
14552 break;
14553
14554 case mfXSWORD:
14555 ft=sXSWORD;
14556 break;
14557
14558 case mfSWORDBEAM:
14559 ft=sSWORDBEAM;
14560 break;
14561
14562 case mfWSWORDBEAM:
14563 ft=sWSWORDBEAM;
14564 break;
14565
14566 case mfMSWORDBEAM:
14567 ft=sMSWORDBEAM;
14568 break;
14569
14570 case mfXSWORDBEAM:
14571 ft=sXSWORDBEAM;
14572 break;
14573
14574 case mfHOOKSHOT:
14575 ft=sHOOKSHOT;
14576 break;
14577
14578 case mfWAND:
14579 ft=sWAND;
14580 break;
14581
14582 case mfHAMMER:
14583 ft=sHAMMER;
14584 break;
14585
14586 case mfSTRIKE:
14587 ft=sSTRIKE;
14588 break;
14589
14590 default:
14591 putit = false;
14592 break;
14593 }
14594
14595 if(putit)
14596 {
14597 s->ffcs[i].data = s->secretcombo[ft];
14598 s->ffcs[i].cset = s->secretcset[ft];
14599 }
14600 }
14601 }
14602
14603 if(!(s->flags2&fCLEARSECRET) || high16only || s->flags4&fENEMYSCRTPERM)
14604 {
14605 for(int32_t iter=0; iter<1; ++iter)
14606 {
14607 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
14608
14609 if(iter==1)
14610 {
14611 // FFCs can't have flags! Yet...
14612 }
14613
14614 if((checkflag > 15)&&(checkflag < 32))
14615 {
14616 s->ffcs[i].data = s->secretcombo[checkflag - 16 + 4];
14617 s->ffcs[i].cset = s->secretcset[checkflag-16+4];
14618 // putit = true;
14619 }
14620 }
14621 }
14622 }
14623 }
14624